Skip to content

Commit 2bd23cf

Browse files
feat(api): add support for tmApprovedSuggestionsOnly parameter in Create Project API (#349)
1 parent 61ef9db commit 2bd23cf

File tree

8 files changed

+107
-8
lines changed

8 files changed

+107
-8
lines changed

src/Crowdin.Api/ProjectsGroups/AddProjectRequest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using JetBrains.Annotations;
33

44
#nullable enable
@@ -10,4 +10,4 @@ public class AddProjectRequest
1010
{
1111

1212
}
13-
}
13+
}

src/Crowdin.Api/ProjectsGroups/EnterpriseProjectForm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using System.Collections.Generic;
33
using JetBrains.Annotations;
44
using Newtonsoft.Json;
@@ -124,5 +124,8 @@ public class EnterpriseProjectForm : AddProjectRequest
124124

125125
[JsonProperty("defaultGlossaryId")]
126126
public long? DefaultGlossaryId { get; set; }
127+
128+
[JsonProperty("tmApprovedSuggestionsOnly")]
129+
public bool? TmApprovedSuggestionsOnly { get; set; }
127130
}
128131
}

src/Crowdin.Api/ProjectsGroups/FileBasedProjectForm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using System.Collections.Generic;
33
using JetBrains.Annotations;
44
using Newtonsoft.Json;
@@ -115,5 +115,8 @@ public class FileBasedProjectForm : ProjectForm
115115

116116
[JsonProperty("defaultGlossaryId")]
117117
public long? DefaultGlossaryId { get; set; }
118+
119+
[JsonProperty("tmApprovedSuggestionsOnly")]
120+
public bool? TmApprovedSuggestionsOnly { get; set; }
118121
}
119122
}

src/Crowdin.Api/ProjectsGroups/ProjectSettings.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using System.Collections.Generic;
33

44
using JetBrains.Annotations;
@@ -115,5 +115,8 @@ public class ProjectSettings : Project
115115
[JsonProperty("tmPenalties")]
116116
[JsonConverter(typeof(EmptyArrayAsObjectConverter))]
117117
public TmPenalties TmPenalties { get; set; }
118+
119+
[JsonProperty("tmApprovedSuggestionsOnly")]
120+
public bool? TmApprovedSuggestionsOnly { get; set; }
118121
}
119122
}

src/Crowdin.Api/ProjectsGroups/StringsBasedProjectForm.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using System.Collections.Generic;
33
using JetBrains.Annotations;
44
using Newtonsoft.Json;
@@ -115,5 +115,8 @@ public class StringsBasedProjectForm : ProjectForm
115115

116116
[JsonProperty("defaultGlossaryId")]
117117
public long? DefaultGlossaryId { get; set; }
118+
119+
[JsonProperty("tmApprovedSuggestionsOnly")]
120+
public bool? TmApprovedSuggestionsOnly { get; set; }
118121
}
119122
}

tests/Crowdin.Api.UnitTesting/Resources/Projects.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/Crowdin.Api.UnitTesting/Resources/Projects.resx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
1+
<?xml version="1.0" encoding="utf-8"?>
22

33
<root>
44
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
@@ -315,4 +315,10 @@
315315
<data name="AddProject_RightRequestJson_EnumsTest" xml:space="preserve">
316316
<value>{"languageAccessPolicy":"open","translateDuplicates":4}</value>
317317
</data>
318+
<data name="AddProject_RightRequestJson_TmApprovedSuggestionsOnlyTest_ForStandardProject" xml:space="preserve">
319+
<value>{"name":"Test Standard Project","sourceLanguageId":"en","tmApprovedSuggestionsOnly":true}</value>
320+
</data>
321+
<data name="AddProject_RightRequestJson_TmApprovedSuggestionsOnlyTest_ForEnterpriseProject" xml:space="preserve">
322+
<value>{"name":"Test Enterprise Project","sourceLanguageId":"en","tmApprovedSuggestionsOnly":false}</value>
323+
</data>
318324
</root>

tests/Crowdin.Api.UnitTesting/Tests/ProjectsGroups/ProjectsApiTests.cs

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-

1+
22
using System.Collections.Generic;
33
using System.Linq;
44
using System.Net;
@@ -149,5 +149,68 @@ public async Task AddProject_TestEnumsConversion()
149149

150150
Assert.NotNull(projectResponse);
151151
}
152+
153+
[Fact]
154+
public async Task AddProject_ShouldIncludeTmApprovedSuggestionsOnly_ForStandardProject()
155+
{
156+
var request = new FileBasedProjectForm
157+
{
158+
Name = "Test Standard Project",
159+
SourceLanguageId = "en",
160+
TmApprovedSuggestionsOnly = true
161+
};
162+
163+
JsonSerializerSettings options = TestUtils.CreateJsonSerializerOptions();
164+
Mock<ICrowdinApiClient> mockClient = TestUtils.CreateMockClientWithDefaultParser();
165+
166+
string requestJson = JsonConvert.SerializeObject(request, options);
167+
string rightRequestJson = Projects.AddProject_RightRequestJson_TmApprovedSuggestionsOnlyTest_ForStandardProject;
168+
Assert.Equal(rightRequestJson, requestJson);
169+
170+
mockClient
171+
.Setup(client => client.SendPostRequest("/projects", request, null))
172+
.ReturnsAsync(new CrowdinApiResult
173+
{
174+
StatusCode = HttpStatusCode.Created,
175+
JsonObject = JObject.Parse(Projects.AddProject_RightResponseJson_ProjectInfo)
176+
});
177+
178+
var executor = new ProjectsGroupsApiExecutor(mockClient.Object);
179+
var projectResponse = await executor.AddProject<Project>(request);
180+
181+
Assert.NotNull(projectResponse);
182+
}
183+
184+
[Fact]
185+
public async Task AddProject_ShouldIncludeTmApprovedSuggestionsOnly_ForEnterpriseProject()
186+
{
187+
var request = new EnterpriseProjectForm
188+
{
189+
Name = "Test Enterprise Project",
190+
SourceLanguageId = "en",
191+
TmApprovedSuggestionsOnly = false
192+
};
193+
194+
JsonSerializerSettings options = TestUtils.CreateJsonSerializerOptions();
195+
Mock<ICrowdinApiClient> mockClient = TestUtils.CreateMockClientWithDefaultParser();
196+
197+
string requestJson = JsonConvert.SerializeObject(request, options);
198+
string rightRequestJson = Projects.AddProject_RightRequestJson_TmApprovedSuggestionsOnlyTest_ForEnterpriseProject;
199+
Assert.Equal(rightRequestJson, requestJson);
200+
201+
mockClient
202+
.Setup(client => client.SendPostRequest("/projects", request, null))
203+
.ReturnsAsync(new CrowdinApiResult
204+
{
205+
StatusCode = HttpStatusCode.Created,
206+
JsonObject = JObject.Parse(Projects.AddProject_RightResponseJson_ProjectInfo)
207+
});
208+
209+
var executor = new ProjectsGroupsApiExecutor(mockClient.Object);
210+
var projectResponse = await executor.AddProject<Project>(request);
211+
212+
Assert.NotNull(projectResponse);
213+
}
214+
152215
}
153216
}

0 commit comments

Comments
 (0)