-
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.
feat: add usecase for fetching tokens
- Loading branch information
Showing
13 changed files
with
198 additions
and
4 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
12 changes: 12 additions & 0 deletions
12
packages/runtime/src/extensibility/facades/transport/TagsFacade.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,12 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { BackboneGetTag } from "@nmshd/transport/src/modules/tags/backbone/BackboneGetTag"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { GetTagsUseCase } from "../../.."; | ||
|
||
export class TagsFacade { | ||
public constructor(@Inject private readonly getTagsUseCase: GetTagsUseCase) {} | ||
|
||
public async getTags(): Promise<Result<BackboneGetTag>> { | ||
return await this.getTagsUseCase.execute(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Result } from "@js-soft/ts-utils"; | ||
import { TagController } from "@nmshd/transport/src/modules/tags/TagController"; | ||
import { BackboneGetTag } from "@nmshd/transport/src/modules/tags/backbone/BackboneGetTag"; | ||
import { Inject } from "@nmshd/typescript-ioc"; | ||
import { UseCase } from "../../common"; | ||
|
||
export class GetTagsUseCase extends UseCase<void, BackboneGetTag> { | ||
public constructor(@Inject private readonly tagController: TagController) { | ||
super(); | ||
} | ||
|
||
protected async executeInternal(): Promise<Result<BackboneGetTag>> { | ||
return Result.ok(await this.tagController.getTags()); | ||
} | ||
} |
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 @@ | ||
export * from "./GetTags"; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AccountController, ControllerName, TransportController } from "../.."; | ||
import { BackboneGetTag } from "./backbone/BackboneGetTag"; | ||
import { TagClient } from "./backbone/TagClient"; | ||
|
||
export class TagController extends TransportController { | ||
private client: TagClient; | ||
|
||
public constructor(parent: AccountController) { | ||
super(ControllerName.Tag, parent); | ||
} | ||
|
||
public override async init(): Promise<this> { | ||
await super.init(); | ||
|
||
this.client = new TagClient(this.config, this.parent.authenticator, this.transport.correlator); | ||
|
||
return this; | ||
} | ||
|
||
public async getTags(): Promise<BackboneGetTag> { | ||
const tags = (await this.client.getTags()).value; | ||
return tags; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
packages/transport/src/modules/tags/backbone/BackboneGetTag.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 BackboneGetTag { | ||
supportedLanguages: string[]; | ||
tagsForAttributeValueTypes: Record<string, Record<string, Tag>>; | ||
} | ||
|
||
interface Tag { | ||
displayNames: Record<string, string>; | ||
children?: Record<string, Tag>; | ||
} |
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 @@ | ||
import { ClientResult } from "../../../core/backbone/ClientResult"; | ||
import { RESTClientAuthenticate } from "../../../core/backbone/RESTClientAuthenticate"; | ||
import { BackboneGetTag } from "./BackboneGetTag"; | ||
|
||
export class TagClient extends RESTClientAuthenticate { | ||
public async getTags(): Promise<ClientResult<BackboneGetTag>> { | ||
return await this.get<BackboneGetTag>("/api/v1/Tags"); | ||
} | ||
} |
111 changes: 111 additions & 0 deletions
111
packages/transport/test/modules/tags/TagsController.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,111 @@ | ||
import { IDatabaseConnection } from "@js-soft/docdb-access-abstractions"; | ||
import { AccountController, ClientResult, Transport } from "../../../src"; | ||
import { BackboneGetTag } from "../../../src/modules/tags/backbone/BackboneGetTag"; | ||
import { TagClient } from "../../../src/modules/tags/backbone/TagClient"; | ||
import { TestUtil } from "../../testHelpers/TestUtil"; | ||
|
||
describe("AccountController", function () { | ||
let connection: IDatabaseConnection; | ||
|
||
let transport: Transport; | ||
|
||
let account: AccountController; | ||
|
||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
const mockTags: BackboneGetTag = { | ||
supportedLanguages: ["de", "en"], | ||
tagsForAttributeValueTypes: { | ||
IdentityFileReference: { | ||
schulabschluss: { | ||
displayNames: { | ||
de: "Abschluss", | ||
en: "Degree" | ||
}, | ||
children: { | ||
realschule: { | ||
displayNames: { | ||
de: "Realschule", | ||
en: "Secondary School" | ||
}, | ||
children: { | ||
zeugnis: { | ||
displayNames: { | ||
de: "Zeugnis", | ||
en: "Diploma" | ||
} | ||
} | ||
} | ||
}, | ||
|
||
gymnasium: { | ||
displayNames: { | ||
de: "Gymnasium", | ||
en: "High School" | ||
}, | ||
children: { | ||
zeugnis: { | ||
displayNames: { | ||
de: "Zeugnis", | ||
en: "Diploma" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
PhoneNumber: { | ||
notfall: { | ||
displayNames: { | ||
de: "Notfallkontakt", | ||
en: "Emergency Contact" | ||
} | ||
} | ||
}, | ||
StreetAddress: { | ||
lieferung: { | ||
displayNames: { | ||
de: "Lieferadresse", | ||
en: "Deliver Address" | ||
} | ||
}, | ||
heimat: { | ||
displayNames: { | ||
de: "Heimatadresse", | ||
en: "Home Address" | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
/* eslint-enable @typescript-eslint/naming-convention */ | ||
|
||
beforeAll(async function () { | ||
connection = await TestUtil.createDatabaseConnection(); | ||
transport = TestUtil.createTransport(connection); | ||
|
||
await transport.init(); | ||
|
||
const accounts = await TestUtil.provideAccounts(transport, 1); | ||
account = accounts[0]; | ||
const tagClient = (account.tags as any).client as TagClient; | ||
|
||
const mockGetTags = jest.fn().mockImplementation(() => { | ||
return Promise.resolve(ClientResult.ok(mockTags)); | ||
}); | ||
|
||
tagClient.getTags = mockGetTags.bind(tagClient); | ||
}); | ||
|
||
afterAll(async function () { | ||
await account.close(); | ||
|
||
await connection.close(); | ||
}); | ||
|
||
test("should receive the legal tags", async function () { | ||
const tags = await account.tags.getTags(); | ||
|
||
expect(tags).toStrictEqual(mockTags); | ||
}); | ||
}); |