Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue fields and some tests #16

Merged
merged 5 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</PropertyGroup>
<PropertyGroup>
<VersionMajor>2</VersionMajor>
<VersionMinor>0</VersionMinor>
<VersionMinor>1</VersionMinor>
<BuildNumber>$(BuildNumber)</BuildNumber>
<BuildNumber Condition="'$(BuildNumber)' == ''">0</BuildNumber>
<PackageVersion>$(VersionMajor).$(VersionMinor).$(BuildNumber)$(VersionTag)</PackageVersion>
Expand Down
3 changes: 2 additions & 1 deletion Mindbox.YandexTracker.Abstractions/Entities/IssueField.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Text.Json;

namespace Mindbox.YandexTracker;

Expand Down Expand Up @@ -92,5 +93,5 @@ public sealed record OptionsProviderInfo
/// <summary>
/// Массив со значениями поля
/// </summary>
public Collection<object> Values { get; init; } = [];
public Collection<JsonElement> Values { get; init; } = [];
}
18 changes: 9 additions & 9 deletions Mindbox.YandexTracker.Abstractions/Entities/Project.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,38 +61,38 @@ public sealed record Project
/// <summary>
/// Участники проекта
/// </summary>
public Collection<UserShortInfo>? TeamUsers { get; init; }
public Collection<UserShortInfo> TeamUsers { get; init; } = [];

/// <summary>
/// Заказчики
/// </summary>
public Collection<UserShortInfo>? Clients { get; init; }
public Collection<UserShortInfo> Clients { get; init; } = [];

/// <summary>
/// Наблюдатели
/// </summary>
public Collection<UserShortInfo>? Followers { get; init; }
public Collection<UserShortInfo> Followers { get; init; } = [];

/// <summary>
/// Теги
/// </summary>
public Collection<string>? Tags { get; init; }
public Collection<string> Tags { get; init; } = [];

/// <summary>
/// Дата начала
/// </summary>
/// <remarks>
/// Учитывается только год, месяц и день
/// </remarks>
public DateTime? StartUtc { get; init; }
public DateOnly? StartUtc { get; init; }

/// <summary>
/// Дедлайн
/// </summary>
/// <remarks>
/// Учитывается только год, месяц и день
/// </remarks>
public DateTime? EndUtc { get; init; }
public DateOnly? EndUtc { get; init; }

/// <summary>
/// Доступ
Expand All @@ -107,12 +107,12 @@ public sealed record Project
/// <summary>
/// Кварталы начала и окончания проекта
/// </summary>
public Collection<string>? Quarter { get; init; }
public Collection<string> Quarter { get; init; } = [];

/// <summary>
/// Идентификаторы чеклистов
/// </summary>
public Collection<string>? ChecklistIds { get; init; }
public Collection<string> ChecklistIds { get; init; } = [];

/// <summary>
/// Идентификатор родительского проекта
Expand All @@ -123,7 +123,7 @@ public sealed record Project
/// Очереди задач, содержащихся в проекте
/// </summary>
/// <returns></returns>
public Collection<string>? IssueQueueKeys { get; init; }
public Collection<string> IssueQueueKeys { get; init; } = [];

public override int GetHashCode()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public sealed record UserDetailedInfo
/// <summary>
/// Уникальный идентификатор учетной записи пользователя в Tracker
/// </summary>
public required long Id { get; init; }
public required long Uid { get; init; }

/// <summary>
/// Логин пользователя
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,37 @@ public async Task GetQueuesAsync_ResponseInNotNullAndContainsSomeQueues()
public async Task GetIssueAsync_IssueKey_ResponseIsNotNullAndIssueSuccessfullyCreated()
{
// Arrange

var currentUserShortInfo = new UserShortInfo
{
Display = CurrentUserLogin,
Id = CurrentUserId
};

var nowUtc = DateTime.UtcNow;
var dateTimeOnlyStart = DateOnly.FromDateTime(nowUtc);
var tags = new[] { "tag1", "tag2" };
var summary = GetUniqueName();

var issue = await YandexTrackerClient.CreateIssueAsync(new Issue
{
QueueKey = TestQueueKey,
Summary = GetUniqueName()
Summary = summary,
CreatedBy = currentUserShortInfo,
Description = "DESC",
Tags = tags,
Followers = [currentUserShortInfo],
Assignee = currentUserShortInfo,
Author = currentUserShortInfo,
Priority = Priority.Trivial,
Start = dateTimeOnlyStart,
Type = new IssueType
{
Id = 2,
Name = "Задача",
Key = "task"
},
UpdatedBy = currentUserShortInfo
});

// Act
Expand All @@ -57,6 +84,18 @@ public async Task GetIssueAsync_IssueKey_ResponseIsNotNullAndIssueSuccessfullyCr
// Arrange
Assert.IsNotNull(issue);
Assert.AreEqual(issue.Key, issueResponse.Key);
Assert.AreEqual(summary, issueResponse.Summary);
Assert.AreEqual(dateTimeOnlyStart, issueResponse.Start);
Assert.AreEqual("task", issueResponse.Type.Key);
Assert.AreEqual("DESC", issueResponse.Description);
Assert.AreEqual(Priority.Trivial, issueResponse.Priority);
Assert.AreEqual(currentUserShortInfo.Id, issueResponse.CreatedBy.Id);
Assert.AreEqual(currentUserShortInfo.Id, issueResponse.UpdatedBy.Id);
Assert.AreEqual(currentUserShortInfo.Id, issueResponse.Assignee!.Id);
Assert.AreEqual(1, issueResponse.Followers.Count);
Assert.AreEqual(currentUserShortInfo.Id, issueResponse.Followers.First().Id);
Assert.AreEqual(2, issueResponse.Tags.Count);
CollectionAssert.AreEqual(tags, issueResponse.Tags.ToList());
}

[TestMethod]
Expand Down Expand Up @@ -408,10 +447,12 @@ public async Task GetProjectsAsync_Project_ProjectFields_ResponseIsNotNullAndCon
};

var nowUtc = DateTime.UtcNow;
var endUtc = nowUtc.AddDays(3);
var tags = new Collection<string> { "tag1", "tag2" };
var quarter = new Collection<string>();

var dateOnlyNow = DateOnly.FromDateTime(nowUtc);
var dateOnlyEnd = DateOnly.FromDateTime(nowUtc.AddDays(3));

var project1 = await YandexTrackerClient.CreateProjectAsync(
ProjectEntityType.Project,
new Project
Expand All @@ -424,8 +465,8 @@ public async Task GetProjectsAsync_Project_ProjectFields_ResponseIsNotNullAndCon
Description = "DESC",
Tags = tags,
ProjectType = ProjectEntityType.Project,
StartUtc = nowUtc,
EndUtc = endUtc,
StartUtc = dateOnlyNow,
EndUtc = dateOnlyEnd,
CreatedBy = currentUserShortInfo,
TeamAccess = false,
TeamUsers = [currentUserShortInfo],
Expand Down Expand Up @@ -479,12 +520,8 @@ public async Task GetProjectsAsync_Project_ProjectFields_ResponseIsNotNullAndCon
CollectionAssert.AreEqual(tags, actualProject.Tags);
Assert.AreEqual(ProjectEntityType.Project, actualProject.ProjectType);
Assert.AreEqual(ProjectEntityStatus.InProgress, actualProject.Status);
Assert.IsTrue(nowUtc.Year == actualProject.StartUtc?.Year // Возвращается только год, месяц и день
&& nowUtc.Month == actualProject.StartUtc?.Month
&& nowUtc.Day == actualProject.StartUtc?.Day);
Assert.IsTrue(endUtc.Year == actualProject.EndUtc?.Year // Возвращается только год, месяц и день
&& endUtc.Month == actualProject.EndUtc?.Month
&& endUtc.Day == actualProject.EndUtc?.Day);
Assert.AreEqual(dateOnlyNow, actualProject.StartUtc);
Assert.AreEqual(dateOnlyEnd, actualProject.EndUtc);
Assert.AreEqual(currentUserShortInfo.Id, actualProject.CreatedBy.Id);
Assert.IsNull(actualProject.TeamAccess);
Assert.AreEqual(1, actualProject.TeamUsers!.Count);
Expand Down
8 changes: 4 additions & 4 deletions Mindbox.YandexTracker.Tests/UnitTests/HashCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public void GetHashCode_TwoSimilarProjects_HashCodeShouldBeEqual()
Id = authorUserId,
Display = "displayw"
},
EndUtc = future.AddDays(-3),
EndUtc = DateOnly.FromDateTime(future.AddDays(-3)),
Lead = new UserShortInfo
{
Id = authorUserId,
Expand All @@ -119,7 +119,7 @@ public void GetHashCode_TwoSimilarProjects_HashCodeShouldBeEqual()
Quarter = ["q1", "q2"],
ParentId = 3,
Description = "project for project",
StartUtc = future.AddDays(2),
StartUtc = DateOnly.FromDateTime(future.AddDays(2)),
Status = ProjectEntityStatus.Draft,
Summary = "summary",
ShortId = 2
Expand Down Expand Up @@ -147,7 +147,7 @@ public void GetHashCode_TwoSimilarProjects_HashCodeShouldBeEqual()
Id = authorUserId,
Display = "displayw"
},
EndUtc = future.AddDays(-3),
EndUtc = DateOnly.FromDateTime(future.AddDays(-3)),
Lead = new UserShortInfo
{
Id = authorUserId,
Expand All @@ -156,7 +156,7 @@ public void GetHashCode_TwoSimilarProjects_HashCodeShouldBeEqual()
Quarter = ["q1", "q2"],
ParentId = 3,
Description = "project for project",
StartUtc = future.AddDays(2),
StartUtc = DateOnly.FromDateTime(future.AddDays(2)),
Status = ProjectEntityStatus.Draft,
Summary = "summary",
ShortId = 2
Expand Down
2 changes: 1 addition & 1 deletion Mindbox.YandexTracker.Tests/YandexTrackerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static async Task TestInitializeAsync(TestContext context)

// узнаем инфу о пользователи, от имени которого выполняем запрос
var userInfo = await YandexTrackerClient.GetMyselfAsync();
CurrentUserId = userInfo.Id.ToString(CultureInfo.InvariantCulture);
CurrentUserId = userInfo.Uid.ToString(CultureInfo.InvariantCulture);
CurrentUserLogin = userInfo.Login;

// в ключе может быть до 15 латинских символов
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text.Json;
Expand All @@ -19,6 +20,8 @@ internal sealed record CreateIssueRequest

public string? Parent { get; init; }

public DateOnly? Start { get; init; }

public string? Author { get; init; }

public string? Unique { get; init; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ internal sealed record ProjectFieldsDto
/// <remarks>
/// Must have YYYY-MM-DDThh:mm:ss.sss±hhmm format
/// </remarks>
public DateTime? Start { get; init; }
public DateOnly? Start { get; init; }

/// <remarks>
/// Must have YYYY-MM-DDThh:mm:ss.sss±hhmm format
/// </remarks>
public DateTime? End { get; init; }
public DateOnly? End { get; init; }

public Collection<string>? Tags { get; init; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ internal sealed record CreateIssueResponse

public required FieldInfo UpdatedBy { get; init; }

public FieldInfo? Author { get; init; }

public string? Description { get; init; }

[JsonPropertyName("sprint")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System.Text.Json;

namespace Mindbox.YandexTracker;

Expand All @@ -10,6 +11,8 @@ internal sealed record GetIssueFieldsResponse

public required string Name { get; init; }

public string? Description { get; init; }

public bool Readonly { get; init; }

public bool Options { get; init; }
Expand Down Expand Up @@ -49,5 +52,5 @@ internal class OptionsProviderInfoDto
{
public required string Type { get; init; }

public Collection<object> Values { get; init; } = [];
public Collection<JsonElement> Values { get; init; } = [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ internal sealed record GetIssueResponse

public required FieldInfo Type { get; init; }

public FieldInfo? Author { get; init; }

public required FieldInfo Priority { get; init; }

public DateTime CreatedAt { get; init; }
Expand All @@ -51,7 +53,7 @@ internal sealed record GetIssueResponse

public FieldInfo? PreviousStatus { get; init; }

public bool IsFavorite { get; init; }
public bool Favorite { get; init; }

public DateOnly? Start { get; set; }

Expand Down
19 changes: 13 additions & 6 deletions Mindbox.YandexTracker/Extensions/JsonElementExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using System.Text.Json;

namespace Mindbox.YandexTracker;
Expand All @@ -7,10 +8,13 @@ internal static class JsonElementExtensions
{
public static UserShortInfo ToUserShortInfo(this JsonElement element)
{
var display = element.GetProperty("display").GetString();
var id = element.GetProperty("id").GetString();

return new UserShortInfo
{
Display = element.GetProperty("display").GetString() ?? string.Empty,
Id = element.GetProperty("id").GetString() ?? string.Empty
Display = display ?? throw new ArgumentNullException(display),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

А точно исключение кидать надо? Эти оба поля обязательные?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Плюс там еще ниже есть точно такой же кейс. ToFieldInfoCollection например.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поля обязательные. Второй кейс поправил, там только поле Key необязательное

Id = id ?? throw new ArgumentNullException(id)
};
}

Expand Down Expand Up @@ -49,11 +53,14 @@ public static Collection<FieldInfo> ToFieldInfoCollection(this JsonElement eleme

foreach (var item in element.EnumerateArray())
{
var display = item.GetProperty("display").GetString();
var id = item.GetProperty("id").GetString();

collection.Add(new FieldInfo
{
Id = item.GetProperty("id").GetString() ?? string.Empty,
Key = item.GetProperty("key").GetString() ?? string.Empty,
Display = item.GetProperty("display").GetString() ?? string.Empty
Id = id ?? throw new ArgumentNullException(id),
Key = item.GetProperty("key").GetString(),
Display = display ?? throw new ArgumentNullException(display)
});
}

Expand Down
Loading
Loading