-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/uniqueness-of-key-for-relationshipattributes' o…
…f github.com:nmshd/runtime into feature/uniqueness-of-key-for-relationshipattributes
- Loading branch information
Showing
16 changed files
with
2,106 additions
and
1,346 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
packages/consumption/src/modules/attributes/local/AttributeTagCollection.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,37 @@ | ||
import { Serializable, serialize, type, validate } from "@js-soft/ts-serval"; | ||
|
||
export interface IAttributeTagCollection { | ||
supportedLanguages: string[]; | ||
tagsForAttributeValueTypes: Record<string, Record<string, IAttributeTag>>; | ||
} | ||
|
||
export interface IAttributeTag { | ||
displayNames: Record<string, string>; | ||
children?: Record<string, IAttributeTag>; | ||
} | ||
|
||
@type("AttributeTagCollection") | ||
export class AttributeTagCollection extends Serializable implements IAttributeTagCollection { | ||
@serialize({ type: String }) | ||
@validate() | ||
public supportedLanguages: string[]; | ||
|
||
@serialize() | ||
@validate() | ||
public tagsForAttributeValueTypes: Record<string, Record<string, AttributeTag>>; | ||
|
||
public static from(value: IAttributeTagCollection): AttributeTagCollection { | ||
return this.fromAny(value); | ||
} | ||
} | ||
|
||
@type("AttributeTag") | ||
export class AttributeTag extends Serializable implements IAttributeTag { | ||
@serialize() | ||
@validate() | ||
public displayNames: Record<string, string>; | ||
|
||
@serialize() | ||
@validate({ nullable: true }) | ||
public children?: Record<string, AttributeTag>; | ||
} |
77 changes: 77 additions & 0 deletions
77
packages/consumption/test/modules/attributes/AttributeTagCollection.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,77 @@ | ||
import { IDatabaseConnection } from "@js-soft/docdb-access-abstractions"; | ||
import { AccountController, ClientResult, TagClient, Transport } from "@nmshd/transport"; | ||
import { spy, when } from "ts-mockito"; | ||
import { AttributeTagCollection, ConsumptionController } from "../../../src"; | ||
import { TestUtil } from "../../core/TestUtil"; | ||
|
||
describe("AttributeTagCollection", function () { | ||
let connection: IDatabaseConnection; | ||
|
||
let transport: Transport; | ||
|
||
let consumptionController: ConsumptionController; | ||
let accountController: AccountController; | ||
|
||
let mockedClient: TagClient; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const mockTags = { | ||
supportedLanguages: ["de", "en"], | ||
tagsForAttributeValueTypes: { | ||
PhoneNumber: { | ||
emergency: { | ||
displayNames: { | ||
de: "Notfallkontakt", | ||
en: "Emergency Contact" | ||
}, | ||
children: { | ||
first: { | ||
displayNames: { | ||
de: "Erster Notfallkontakt", | ||
en: "First Emergency Contact" | ||
} | ||
}, | ||
second: { | ||
displayNames: { | ||
de: "Zweiter Notfallkontakt", | ||
en: "Second Emergency Contact" | ||
} | ||
} | ||
} | ||
}, | ||
private: { | ||
displayNames: { | ||
de: "Privat", | ||
en: "Private" | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
|
||
beforeAll(async function () { | ||
connection = await TestUtil.createConnection(); | ||
transport = TestUtil.createTransport(connection); | ||
|
||
await transport.init(); | ||
|
||
({ consumptionController, accountController } = (await TestUtil.provideAccounts(transport, 1))[0]); | ||
|
||
const client = consumptionController.attributes["attributeTagClient"]; | ||
mockedClient = spy(client); | ||
}); | ||
|
||
afterAll(async function () { | ||
await accountController.close(); | ||
|
||
await connection.close(); | ||
}); | ||
|
||
test("should receive the legal tags from the Backbone", async function () { | ||
when(mockedClient.getTagCollection()).thenResolve(ClientResult.ok(mockTags)); | ||
const tags = await consumptionController.attributes.getAttributeTagCollection(); | ||
|
||
expect(tags).toStrictEqual(AttributeTagCollection.from(mockTags)); | ||
}); | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
packages/runtime/src/types/consumption/AttributeTagCollectionDTO.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,9 @@ | ||
export interface AttributeTagCollectionDTO { | ||
supportedLanguages: string[]; | ||
tagsForAttributeValueTypes: Record<string, Record<string, AttributeTagDTO>>; | ||
} | ||
|
||
export interface AttributeTagDTO { | ||
displayNames: Record<string, string>; | ||
children?: Record<string, AttributeTagDTO>; | ||
} |
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
39 changes: 39 additions & 0 deletions
39
packages/runtime/src/useCases/consumption/attributes/AttributeTagCollectionMapper.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,39 @@ | ||
import { AttributeTag, AttributeTagCollection } from "@nmshd/consumption"; | ||
import { AttributeTagCollectionDTO, AttributeTagDTO } from "../../../types"; | ||
|
||
export class AttributeTagCollectionMapper { | ||
public static toAttributeTagCollectionDTO(tagList: AttributeTagCollection): AttributeTagCollectionDTO { | ||
return { | ||
supportedLanguages: tagList.supportedLanguages, | ||
tagsForAttributeValueTypes: Object.entries(tagList.tagsForAttributeValueTypes).reduce( | ||
(acc, [key, value]) => { | ||
acc[key] = Object.entries(value).reduce( | ||
(acc2, [key2, value2]) => { | ||
acc2[key2] = AttributeTagCollectionMapper.toAttributeTagDTO(value2); | ||
return acc2; | ||
}, | ||
{} as Record<string, AttributeTagDTO> | ||
); | ||
return acc; | ||
}, | ||
{} as Record<string, Record<string, AttributeTagDTO>> | ||
) | ||
}; | ||
} | ||
|
||
public static toAttributeTagDTO(tagListDTO: AttributeTag): AttributeTagDTO { | ||
const tagDTO: AttributeTagDTO = { | ||
displayNames: tagListDTO.displayNames | ||
}; | ||
if (tagListDTO.children) { | ||
tagDTO.children = Object.entries(tagListDTO.children).reduce( | ||
(acc, [key, value]) => { | ||
acc[key] = AttributeTagCollectionMapper.toAttributeTagDTO(value); | ||
return acc; | ||
}, | ||
{} as Record<string, AttributeTagDTO> | ||
); | ||
} | ||
return tagDTO; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
packages/runtime/src/useCases/consumption/attributes/GetAttributeTagCollection.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,17 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { AttributesController } from "@nmshd/consumption"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { AttributeTagCollectionDTO } from "../../../types"; | ||
import { UseCase } from "../../common"; | ||
import { AttributeTagCollectionMapper } from "./AttributeTagCollectionMapper"; | ||
|
||
export class GetAttributeTagCollectionUseCase extends UseCase<void, AttributeTagCollectionDTO> { | ||
public constructor(@Inject private readonly attributesController: AttributesController) { | ||
super(); | ||
} | ||
|
||
protected async executeInternal(): Promise<Result<AttributeTagCollectionDTO>> { | ||
const attributeTagCollection = await this.attributesController.getAttributeTagCollection(); | ||
return Result.ok(AttributeTagCollectionMapper.toAttributeTagCollectionDTO(attributeTagCollection)); | ||
} | ||
} |
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
65 changes: 65 additions & 0 deletions
65
packages/runtime/test/consumption/attributeTagCollection.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,65 @@ | ||
import { ClientResult, TagClient } from "@nmshd/transport"; | ||
import { reset, spy, when } from "ts-mockito"; | ||
import { RuntimeServiceProvider, TestRuntimeServices } from "../lib"; | ||
|
||
const serviceProvider = new RuntimeServiceProvider(); | ||
let runtimeService: TestRuntimeServices; | ||
|
||
let mockedRestClient: TagClient; | ||
|
||
beforeAll(async () => { | ||
runtimeService = (await serviceProvider.launch(1))[0]; | ||
const client = runtimeService.consumption.attributes["getAttributeTagCollectionUseCase"]["attributesController"]["attributeTagClient"] as TagClient; | ||
mockedRestClient = spy(client); | ||
}, 30000); | ||
|
||
afterAll(() => serviceProvider.stop()); | ||
|
||
afterEach(() => { | ||
reset(mockedRestClient); | ||
}); | ||
|
||
describe("get attributeTagCollection", function () { | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const mockTags = { | ||
supportedLanguages: ["de", "en"], | ||
tagsForAttributeValueTypes: { | ||
PhoneNumber: { | ||
emergency: { | ||
displayNames: { | ||
de: "Notfallkontakt", | ||
en: "Emergency Contact" | ||
}, | ||
children: { | ||
first: { | ||
displayNames: { | ||
de: "Erster Notfallkontakt", | ||
en: "First Emergency Contact" | ||
} | ||
}, | ||
second: { | ||
displayNames: { | ||
de: "Zweiter Notfallkontakt", | ||
en: "Second Emergency Contact" | ||
} | ||
} | ||
} | ||
}, | ||
private: { | ||
displayNames: { | ||
de: "Privat", | ||
en: "Private" | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
|
||
test("should receive the legal tags from the Backbone", async function () { | ||
when(mockedRestClient.getTagCollection()).thenResolve(ClientResult.ok(mockTags)); | ||
const tags = await runtimeService.consumption.attributes.getAttributeTagCollection(); | ||
|
||
expect(tags.value).toStrictEqual(mockTags); | ||
}); | ||
}); |
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
9 changes: 9 additions & 0 deletions
9
packages/transport/src/modules/tags/backbone/BackboneGetTagCollection.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,9 @@ | ||
export interface BackboneGetTagCollection { | ||
supportedLanguages: string[]; | ||
tagsForAttributeValueTypes: Record<string, Record<string, BackboneGetTag>>; | ||
} | ||
|
||
interface BackboneGetTag { | ||
displayNames: Record<string, string>; | ||
children?: Record<string, BackboneGetTag>; | ||
} |
Oops, something went wrong.