-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: [#176740861] Remove from store/readState a not found service (#2868
) * [#176740861] add reducer logic and tests * [#176740861] update comment Co-authored-by: Cristiano Tofani <[email protected]>
- Loading branch information
1 parent
6e44188
commit 64c4a41
Showing
4 changed files
with
68 additions
and
1 deletion.
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
53 changes: 53 additions & 0 deletions
53
ts/store/reducers/entities/services/__tests__/readStateByServiceId.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,53 @@ | ||
import { OrganizationFiscalCode } from "italia-ts-commons/lib/strings"; | ||
import { appReducer } from "../../../index"; | ||
import { | ||
loadServiceDetailNotFound, | ||
markServiceAsRead, | ||
showServiceDetails | ||
} from "../../../../actions/services"; | ||
import { ServicePublic } from "../../../../../../definitions/backend/ServicePublic"; | ||
import { ServiceId } from "../../../../../../definitions/backend/ServiceId"; | ||
import { ServiceName } from "../../../../../../definitions/backend/ServiceName"; | ||
import { NotificationChannelEnum } from "../../../../../../definitions/backend/NotificationChannel"; | ||
import { OrganizationName } from "../../../../../../definitions/backend/OrganizationName"; | ||
import { DepartmentName } from "../../../../../../definitions/backend/DepartmentName"; | ||
|
||
const mockService: ServicePublic = { | ||
department_name: "dev department name" as DepartmentName, | ||
organization_fiscal_code: "00000000001" as OrganizationFiscalCode, | ||
organization_name: "Ramella, Zanetti and Maggiani [1]" as OrganizationName, | ||
service_id: "id1" as ServiceId, | ||
service_name: "reinventate next-generation architetture" as ServiceName, | ||
available_notification_channels: [NotificationChannelEnum.EMAIL], | ||
version: 1 | ||
}; | ||
|
||
describe("readServicesByIdReducer", () => { | ||
it("should be read", () => { | ||
const state = appReducer(undefined, showServiceDetails(mockService)); | ||
expect(state.entities.services.readState.id1).toBeTruthy(); | ||
}); | ||
|
||
it("should be read", () => { | ||
const state = appReducer(undefined, markServiceAsRead("id2" as ServiceId)); | ||
expect(state.entities.services.readState.id2).toBeTruthy(); | ||
}); | ||
|
||
it("should be undefined", () => { | ||
const state = appReducer(undefined, showServiceDetails(mockService)); | ||
expect(state.entities.services.readState.id3).toBeUndefined(); | ||
}); | ||
|
||
it("should remove a specific not found service read state", () => { | ||
const state1 = appReducer(undefined, markServiceAsRead("id1" as ServiceId)); | ||
const state2 = appReducer(state1, markServiceAsRead("id2" as ServiceId)); | ||
expect(state2.entities.services.readState.id1).toBeTruthy(); | ||
expect(state2.entities.services.readState.id2).toBeTruthy(); | ||
const updateState = appReducer( | ||
state2, | ||
loadServiceDetailNotFound("id1" as ServiceId) | ||
); | ||
expect(updateState.entities.services.readState.id1).toBeUndefined(); | ||
expect(state2.entities.services.readState.id2).toBeTruthy(); | ||
}); | ||
}); |
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