-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
12696 automatically add payment data type to applicationmetadata when…
… adding payment task (#12776) * Add/delete dataType when taskType is payment or signing * Support multiple data types for multiple payment or signing tasks * Fix PR comments
- Loading branch information
Showing
25 changed files
with
582 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...gner.Tests/Controllers/ProcessModelingController/AddDataTypeToApplicationMetadataTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
using Designer.Tests.Controllers.ApiTests; | ||
using Designer.Tests.Utils; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Controllers.ProcessModelingController | ||
{ | ||
public class AddDataTypeToApplicationMetadataTests : DisagnerEndpointsTestsBase<AddDataTypeToApplicationMetadataTests>, IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
private static string VersionPrefix(string org, string repository, string dataTypeId) => $"/designer/api/{org}/{repository}/process-modelling/data-type/{dataTypeId}"; | ||
|
||
public AddDataTypeToApplicationMetadataTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("ttd", "empty-app", "testUser", "paymentInformation-1234")] | ||
public async Task AddDataTypeToApplicationMetadata_ShouldAddDataTypeAndReturnOK(string org, string app, string developer, string dataTypeId) | ||
{ | ||
string targetRepository = TestDataHelper.GenerateTestRepoName(); | ||
await CopyRepositoryForTest(org, app, developer, targetRepository); | ||
string url = VersionPrefix(org, targetRepository, dataTypeId); | ||
|
||
using var request = new HttpRequestMessage(HttpMethod.Post, url); | ||
using var response = await HttpClient.SendAsync(request); | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
string appMetadataString = TestDataHelper.GetFileFromRepo(org, targetRepository, developer, "App/config/applicationmetadata.json"); | ||
Application appMetadata = JsonSerializer.Deserialize<Application>(appMetadataString, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
DataType expectedDataType = new() | ||
{ | ||
Id = dataTypeId, | ||
AllowedContentTypes = new List<string>() { "application/json" }, | ||
MaxCount = 1, | ||
MinCount = 0, | ||
EnablePdfCreation = false, | ||
EnableFileScan = false, | ||
ValidationErrorOnPendingFileScan = false, | ||
EnabledFileAnalysers = new List<string>(), | ||
EnabledFileValidators = new List<string>() | ||
}; | ||
|
||
appMetadata.DataTypes.Count.Should().Be(2); | ||
appMetadata.DataTypes.Find(dataType => dataType.Id == dataTypeId).Should().BeEquivalentTo(expectedDataType); | ||
} | ||
|
||
[Theory] | ||
[InlineData("ttd", "empty-app", "testUser", "ref-data-as-pdf")] | ||
public async Task AddDataTypeToApplicationMetadataWhenExists_ShouldNotAddDataTypeAndReturnOK(string org, string app, string developer, string dataTypeId) | ||
{ | ||
string targetRepository = TestDataHelper.GenerateTestRepoName(); | ||
await CopyRepositoryForTest(org, app, developer, targetRepository); | ||
string url = VersionPrefix(org, targetRepository, dataTypeId); | ||
using var request = new HttpRequestMessage(HttpMethod.Post, url); | ||
using var response = await HttpClient.SendAsync(request); | ||
|
||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
string appMetadataString = TestDataHelper.GetFileFromRepo(org, targetRepository, developer, "App/config/applicationmetadata.json"); | ||
Application appMetadata = JsonSerializer.Deserialize<Application>(appMetadataString, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
appMetadata.DataTypes.Count.Should().Be(1); | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...Tests/Controllers/ProcessModelingController/DeleteDataTypeFromApplicationMetadataTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using Altinn.Platform.Storage.Interface.Models; | ||
using Designer.Tests.Controllers.ApiTests; | ||
using Designer.Tests.Utils; | ||
using FluentAssertions; | ||
using Microsoft.AspNetCore.Mvc.Testing; | ||
using Xunit; | ||
|
||
namespace Designer.Tests.Controllers.ProcessModelingController | ||
{ | ||
public class DeleteDataTypeFromApplicationMetadataTests : DisagnerEndpointsTestsBase<DeleteDataTypeFromApplicationMetadataTests>, IClassFixture<WebApplicationFactory<Program>> | ||
{ | ||
private static string VersionPrefix(string org, string repository, string dataTypeId) => $"/designer/api/{org}/{repository}/process-modelling/data-type/{dataTypeId}"; | ||
|
||
public DeleteDataTypeFromApplicationMetadataTests(WebApplicationFactory<Program> factory) : base(factory) | ||
{ | ||
} | ||
|
||
[Theory] | ||
[InlineData("ttd", "empty-app", "testUser", "ref-data-as-pdf")] | ||
public async Task DeleteDataTypeFromApplicationMetadata_ShouldDeleteDataTypeAndReturnOK(string org, string app, string developer, string dataTypeId) | ||
{ | ||
string targetRepository = TestDataHelper.GenerateTestRepoName(); | ||
await CopyRepositoryForTest(org, app, developer, targetRepository); | ||
string url = VersionPrefix(org, targetRepository, dataTypeId); | ||
|
||
using var request = new HttpRequestMessage(HttpMethod.Delete, url); | ||
using var response = await HttpClient.SendAsync(request); | ||
response.StatusCode.Should().Be(HttpStatusCode.OK); | ||
|
||
string appMetadataString = TestDataHelper.GetFileFromRepo(org, targetRepository, developer, "App/config/applicationmetadata.json"); | ||
Application appMetadata = JsonSerializer.Deserialize<Application>(appMetadataString, new JsonSerializerOptions | ||
{ | ||
PropertyNameCaseInsensitive = true | ||
}); | ||
|
||
appMetadata.DataTypes.Count.Should().Be(0); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
frontend/app-development/hooks/mutations/useAddDataTypeToAppMetadata.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { renderHookWithMockStore } from '../../test/mocks'; | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { waitFor } from '@testing-library/react'; | ||
import { useAddDataTypeToAppMetadata } from './useAddDataTypeToAppMetadata'; | ||
|
||
const org = 'org'; | ||
const app = 'app'; | ||
const dataTypeId = 'paymentInformation-1234'; | ||
|
||
describe('useAddDataTypeToAppMetadata', () => { | ||
it('Calls addDataTypeToAppMetadata with correct arguments and payload', async () => { | ||
const addDataTypeToAppMetadata = renderHookWithMockStore()(() => | ||
useAddDataTypeToAppMetadata(org, app), | ||
).renderHookResult.result; | ||
await addDataTypeToAppMetadata.current.mutateAsync({ | ||
dataTypeId, | ||
}); | ||
await waitFor(() => expect(addDataTypeToAppMetadata.current.isSuccess).toBe(true)); | ||
|
||
expect(queriesMock.addDataTypeToAppMetadata).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.addDataTypeToAppMetadata).toHaveBeenCalledWith(org, app, dataTypeId); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
frontend/app-development/hooks/mutations/useAddDataTypeToAppMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
|
||
export const useAddDataTypeToAppMetadata = (org: string, app: string) => { | ||
const { addDataTypeToAppMetadata } = useServicesContext(); | ||
|
||
return useMutation({ | ||
mutationFn: ({ dataTypeId }: { dataTypeId: string }) => | ||
addDataTypeToAppMetadata(org, app, dataTypeId), | ||
}); | ||
}; |
23 changes: 23 additions & 0 deletions
23
frontend/app-development/hooks/mutations/useDeleteDataTypeFromAppMetadata.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { renderHookWithMockStore } from '../../test/mocks'; | ||
import { queriesMock } from 'app-shared/mocks/queriesMock'; | ||
import { useDeleteDataTypeFromAppMetadata } from './useDeleteDataTypeFromAppMetadata'; | ||
import { waitFor } from '@testing-library/react'; | ||
|
||
const org = 'org'; | ||
const app = 'app'; | ||
const dataTypeId = 'paymentInformation-1234'; | ||
|
||
describe('useDeleteDataTypeFromAppMetadata', () => { | ||
it('Calls deleteDataTypeFromAppMetadata with correct arguments and payload', async () => { | ||
const deleteDataTypeFromAppMetadata = renderHookWithMockStore()(() => | ||
useDeleteDataTypeFromAppMetadata(org, app), | ||
).renderHookResult.result; | ||
await deleteDataTypeFromAppMetadata.current.mutateAsync({ | ||
dataTypeId, | ||
}); | ||
await waitFor(() => expect(deleteDataTypeFromAppMetadata.current.isSuccess).toBe(true)); | ||
|
||
expect(queriesMock.deleteDataTypeFromAppMetadata).toHaveBeenCalledTimes(1); | ||
expect(queriesMock.deleteDataTypeFromAppMetadata).toHaveBeenCalledWith(org, app, dataTypeId); | ||
}); | ||
}); |
11 changes: 11 additions & 0 deletions
11
frontend/app-development/hooks/mutations/useDeleteDataTypeFromAppMetadata.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { useMutation } from '@tanstack/react-query'; | ||
import { useServicesContext } from 'app-shared/contexts/ServicesContext'; | ||
|
||
export const useDeleteDataTypeFromAppMetadata = (org: string, app: string) => { | ||
const { deleteDataTypeFromAppMetadata } = useServicesContext(); | ||
|
||
return useMutation({ | ||
mutationFn: ({ dataTypeId }: { dataTypeId: string }) => | ||
deleteDataTypeFromAppMetadata(org, app, dataTypeId), | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.