Skip to content
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
3 changes: 3 additions & 0 deletions src/Crowdin.Api/Translations/ApplyPreTranslationRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class ApplyPreTranslationRequest
[JsonProperty("branchIds")]
public ICollection<long>? BranchIds { get; set; }

[JsonProperty("directoryIds")]
public ICollection<long>? DirectoryIds { get; set; }

[JsonProperty("fileIds")]
public ICollection<long>? FileIds { get; set; }

Expand Down
3 changes: 3 additions & 0 deletions src/Crowdin.Api/Translations/PreTranslateAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ public class PreTranslateAttributes
[JsonProperty("branchIds")]
public string[] BranchIds { get; set; } = Array.Empty<string>();

[JsonProperty("directoryIds")]
public long[]? DirectoryIds { get; set; }

[JsonProperty("fileIds")]
public long[]? FileIds { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions tests/Crowdin.Api.UnitTesting/Resources/Translations.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions tests/Crowdin.Api.UnitTesting/Resources/Translations.resx
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,41 @@
"startedAt": "2019-08-24T14:15:22Z",
"finishedAt": "2019-08-24T14:15:22Z"
}
}</value>
</data>
<data name="ApplyPreTranslation_Request_WithDirectoryIds" xml:space="preserve">
<value>{
"languageIds": ["uk"],
"branchIds": [5],
"directoryIds": [10, 11],
"labelIds": [],
"excludeLabelIds": []
}</value>
</data>
<data name="ApplyPreTranslation_Response_WithDirectoryIds" xml:space="preserve">
<value>{
"data": {
"identifier": "9e7de270-4f83-41cb-b606-2f90631f26e2",
"status": "created",
"progress": 0,
"attributes": {
"languageIds": ["uk"],
"branchIds": [5],
"directoryIds": [10, 11],
"method": "tm",
"autoApproveOption": "none",
"duplicateTranslations": false,
"skipApprovedTranslations": false,
"translateUntranslatedOnly": false,
"translateWithPerfectMatchOnly": false,
"labelIds": [],
"excludeLabelIds": []
},
"createdAt": "2019-09-20T14:05:50+00:00",
"updatedAt": "2019-09-20T14:05:50+00:00",
"startedAt": "2019-08-24T14:15:22Z",
"finishedAt": "2019-08-24T14:15:22Z"
}
}</value>
</data>
<data name="RevalidateQaChecks_Request" xml:space="preserve">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,43 @@ public async Task ApplyPreTranslation_WithNewFields()
Assert.True(attributes.ResetApprovalStatus);
}

[Fact]
public async Task ApplyPreTranslation_WithDirectoryIds()
{
const int projectId = 1;

var body = new ApplyPreTranslationRequest
{
LanguageIds = new HashSet<string> { "uk" },
BranchIds = new HashSet<long> { 5 },
DirectoryIds = new HashSet<long> { 10, 11 }
};

string actualRequestJson = JsonConvert.SerializeObject(body, JsonSettings);
string expectedRequestJson = TestUtils.CompactJson(Resources.Translations.ApplyPreTranslation_Request_WithDirectoryIds);
Assert.Equal(expectedRequestJson, actualRequestJson);

var mockClient = new Mock<ICrowdinApiClient>();

mockClient
.Setup(client => client.SendPostRequest(
$"/projects/{projectId}/pre-translations", body, null))
.ReturnsAsync(new CrowdinApiResult
{
StatusCode = HttpStatusCode.Accepted,
JsonObject = JObject.Parse(Resources.Translations.ApplyPreTranslation_Response_WithDirectoryIds)
});

var executor = new TranslationsApiExecutor(mockClient.Object, TestUtils.CreateJsonParser());
PreTranslation preTranslation = await executor.ApplyPreTranslation(projectId, body);

Assert.NotNull(preTranslation);
PreTranslateAttributes? attributes = preTranslation.Attributes;
Assert.NotNull(attributes);
Assert.Equal(new long[] { 10, 11 }, attributes.DirectoryIds);
Assert.Equal(new[] { "5" }, attributes.BranchIds);
}

[Fact]
public async Task UploadTranslations()
{
Expand Down
Loading