diff --git a/alfa-client/libs/command-shared/src/lib/command.util.spec.ts b/alfa-client/libs/command-shared/src/lib/command.util.spec.ts index f3cd21cee6ab8eef273bbc0bd4577b74c18b6e67..7f819fe408d4d4f6134ebccd32adf1c86cc716b4 100644 --- a/alfa-client/libs/command-shared/src/lib/command.util.spec.ts +++ b/alfa-client/libs/command-shared/src/lib/command.util.spec.ts @@ -26,7 +26,7 @@ import { getUrl } from '@ngxp/rest'; import { createCommandErrorResource, createCommandListResource, createCommandResource } from 'libs/command-shared/test/command'; import { CommandLinkRel } from './command.linkrel'; import { CommandErrorMessage } from './command.message'; -import { CommandListResource, CommandResource, CommandStatus } from './command.model'; +import { CommandListResource, CommandOrder, CommandResource, CommandStatus, PendingCommandMap } from './command.model'; import { buildPendingCommandMap, getPendingCommandByOrder, @@ -42,12 +42,12 @@ import { describe('CommandUtil', () => { describe('isRevokeable', () => { it('should return true if Link exists', () => { - const result = isRevokeable(createCommandResource([CommandLinkRel.REVOKE])); + const result: boolean = isRevokeable(createCommandResource([CommandLinkRel.REVOKE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isRevokeable(createCommandResource()); + const result: boolean = isRevokeable(createCommandResource()); expect(result).toBe(false); }); @@ -55,12 +55,12 @@ describe('CommandUtil', () => { describe('isPending', () => { it('should return true if Link exists', () => { - const result = isPending(createCommandResource([CommandLinkRel.UPDATE])); + const result: boolean = isPending(createCommandResource([CommandLinkRel.UPDATE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isPending(createCommandResource()); + const result: boolean = isPending(createCommandResource()); expect(result).toBe(false); }); @@ -68,12 +68,12 @@ describe('CommandUtil', () => { describe('isDone', () => { it('should return true if Link exists', () => { - const result = isDone(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE])); + const result: boolean = isDone(createCommandResource([CommandLinkRel.EFFECTED_RESOURCE])); expect(result).toBe(true); }); it('should return false if Link does NOT exists', () => { - const result = isDone(createCommandResource()); + const result: boolean = isDone(createCommandResource()); expect(result).toBe(false); }); @@ -81,27 +81,27 @@ describe('CommandUtil', () => { describe('hasError', () => { it('should be true if no update link is present and command has error message', () => { - const result = hasCommandError(createCommandErrorResource()); + const result: boolean = hasCommandError(createCommandErrorResource()); expect(result).toBeTruthy(); }); it('should be false if update link is present', () => { - const result = hasCommandError(createCommandResource([CommandLinkRel.UPDATE])); + const result: boolean = hasCommandError(createCommandResource([CommandLinkRel.UPDATE])); expect(result).toBeFalsy(); }); it('should be false if error message is not present', () => { - const result = hasCommandError(createCommandResource()); + const result: boolean = hasCommandError(createCommandResource()); expect(result).toBeFalsy(); }); }); describe('getPendingCommandByOrder', () => { - const order: string = 'dummyOrder'; - const anotherOrder: string = 'anotherOrder'; + const order: CommandOrder = <CommandOrder>'dummyOrder'; + const anotherOrder: CommandOrder = <CommandOrder>'anotherOrder'; it('should return null on non existing pending command', () => { const listResource: CommandListResource = createCommandListResource(); @@ -142,7 +142,7 @@ describe('CommandUtil', () => { }; const commandList: CommandListResource = createCommandListResource([pendingCommand1, pendingCommand2]); - const map = buildPendingCommandMap(commandList); + const map: PendingCommandMap = buildPendingCommandMap(commandList); expect(map[getUrl(pendingCommand1, CommandLinkRel.RELATED_RESOURCE)]).toEqual(createStateResource(pendingCommand1)); expect(map[getUrl(pendingCommand2, CommandLinkRel.RELATED_RESOURCE)]).toEqual(createStateResource(pendingCommand2)); diff --git a/alfa-client/libs/command-shared/src/lib/command.util.ts b/alfa-client/libs/command-shared/src/lib/command.util.ts index 820a223daa245a5e15b94e33ca0be22e43edc944..d804d19ac38b2b12aeefa8db760969ae59529f76 100644 --- a/alfa-client/libs/command-shared/src/lib/command.util.ts +++ b/alfa-client/libs/command-shared/src/lib/command.util.ts @@ -26,7 +26,7 @@ import { getEmbeddedResource, getUrl, hasLink, ResourceUri } from '@ngxp/rest'; import { isEmpty, isNil, isObject } from 'lodash-es'; import { CommandLinkRel, CommandListLinkRel } from './command.linkrel'; import { CommandErrorMessage } from './command.message'; -import { CommandListResource, CommandResource } from './command.model'; +import { CommandListResource, CommandOrder, CommandResource, PendingCommandMap } from './command.model'; export function isRevokeable(commandResource: CommandResource): boolean { return hasLink(commandResource, CommandLinkRel.REVOKE); @@ -52,22 +52,19 @@ export function notHasCommandError(commandResource: CommandResource): boolean { return !hasCommandError(commandResource); } -export function getPendingCommandByOrder(pendingCommands: CommandListResource, commandOrder: any[]): CommandResource { +export function getPendingCommandByOrder(pendingCommands: CommandListResource, commandOrder: CommandOrder[]): CommandResource { const commands: CommandResource[] = getEmbeddedCommandResources(pendingCommands).filter((command: CommandResource) => commandOrder.includes(command.order), ); return commands.length > 0 ? commands[0] : null; } -export function buildPendingCommandMap(commandList: CommandListResource): any { - let map = {}; - const commands: CommandResource[] = getEmbeddedCommandResources(commandList); - commands.forEach((command: CommandResource) => { - if (hasLink(command, CommandLinkRel.RELATED_RESOURCE)) { - map[getUrl(command, CommandLinkRel.RELATED_RESOURCE)] = createStateResource(command); - } - }); - return map; +export function buildPendingCommandMap(commandList: CommandListResource): PendingCommandMap { + return Object.fromEntries( + getEmbeddedCommandResources(commandList) + .filter((command: CommandResource) => hasLink(command, CommandLinkRel.RELATED_RESOURCE)) + .map((command: CommandResource) => [getUrl(command, CommandLinkRel.RELATED_RESOURCE), createStateResource(command)]), + ); } function getEmbeddedCommandResources(commandListResource: CommandListResource): CommandResource[] { diff --git a/alfa-client/libs/command-shared/tsconfig.lib.json b/alfa-client/libs/command-shared/tsconfig.lib.json index 464f01e6b2b218c0f70e15ac25dd8580bdc38f6e..4eed46aa156820e1dc14c526cfaab634541466b9 100644 --- a/alfa-client/libs/command-shared/tsconfig.lib.json +++ b/alfa-client/libs/command-shared/tsconfig.lib.json @@ -2,12 +2,12 @@ "extends": "./tsconfig.json", "compilerOptions": { "outDir": "../../dist/out-tsc", - "target": "es2015", + "target": "ES2022", "declaration": true, "declarationMap": true, "inlineSources": true, "types": [], - "lib": ["dom", "es2018"] + "lib": ["dom", "ES2022"] }, "angularCompilerOptions": { "skipTemplateCodegen": true, diff --git a/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts b/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts index 70e6360f7622e932ef269e54cfebd67fdae19524..ae595493a6c49526b69d1af3ee72984773a75a16 100644 --- a/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts +++ b/alfa-client/libs/vorgang-shared/src/lib/+state/vorgang.reducer.spec.ts @@ -536,7 +536,7 @@ describe('Vorgang Reducer', () => { it('should set pending commands map', () => { const pendingCommandMap: PendingCommandMap = createPendingCommandMap(); jest.spyOn(CommandUtil, 'buildPendingCommandMap').mockReturnValue(pendingCommandMap); - const action = VorgangActions.loadPendingCommandListSuccess({ commandList: createCommandListResource() }); + const action: Action<string> = VorgangActions.loadPendingCommandListSuccess({ commandList: createCommandListResource() }); const state: VorgangState = reducer(initialState, action);