From 24ad007a16a992a200d4b0a91da1787b2438c8b9 Mon Sep 17 00:00:00 2001 From: David Ly Date: Wed, 16 Oct 2024 00:37:53 +0200 Subject: [PATCH] Added state management for pricing api routes --- .../src/state/actions/createdOnePricing.ts | 59 +++++++++++++++++ .../src/state/actions/deletedOnePricing.ts | 64 +++++++++++++++++++ packages/common/src/state/actions/index.ts | 4 ++ .../common/src/state/actions/monkAction.ts | 24 +++++-- .../updatedOneInspectionAdditionalData.ts | 61 ++++++++++++++++++ .../src/state/actions/updatedOnePricing.ts | 56 ++++++++++++++++ packages/common/src/state/reducer.ts | 25 ++++++++ packages/common/src/state/state.ts | 6 ++ .../state/actions/createdOnePricing.test.ts | 57 +++++++++++++++++ .../state/actions/deletedOnePricing.test.ts | 53 +++++++++++++++ .../state/actions/gotOneInspection.test.ts | 10 +++ ...updatedOneInspectionAdditionalData.test.ts | 52 +++++++++++++++ .../state/actions/updatedOnePricing.test.ts | 58 +++++++++++++++++ packages/common/test/state/reducer.test.ts | 28 ++++++++ packages/types/src/state/entity.ts | 1 + packages/types/src/state/inspection.ts | 3 +- packages/types/src/state/pricingV2.ts | 4 +- 17 files changed, 558 insertions(+), 7 deletions(-) create mode 100644 packages/common/src/state/actions/createdOnePricing.ts create mode 100644 packages/common/src/state/actions/deletedOnePricing.ts create mode 100644 packages/common/src/state/actions/updatedOneInspectionAdditionalData.ts create mode 100644 packages/common/src/state/actions/updatedOnePricing.ts create mode 100644 packages/common/test/state/actions/createdOnePricing.test.ts create mode 100644 packages/common/test/state/actions/deletedOnePricing.test.ts create mode 100644 packages/common/test/state/actions/updatedOneInspectionAdditionalData.test.ts create mode 100644 packages/common/test/state/actions/updatedOnePricing.test.ts diff --git a/packages/common/src/state/actions/createdOnePricing.ts b/packages/common/src/state/actions/createdOnePricing.ts new file mode 100644 index 000000000..7400dc6eb --- /dev/null +++ b/packages/common/src/state/actions/createdOnePricing.ts @@ -0,0 +1,59 @@ +import { PricingV2Details } from '@monkvision/types'; +import { MonkAction, MonkActionType } from './monkAction'; +import { MonkState } from '../state'; + +/** + * The payload of a MonkCreatedOnePricingPayload. + */ +export interface MonkCreatedOnePricingPayload { + /** + * The pricing created. + */ + pricing: PricingV2Details; +} + +/** + * Action dispatched when a vehicle have been updated. + */ +export interface MonkCreatedOnePricingAction extends MonkAction { + /** + * The type of the action : `MonkActionType.CREATED_ONE_PRICING`. + */ + type: MonkActionType.CREATED_ONE_PRICING; + /** + * The payload of the action containing the fetched entities. + */ + payload: MonkCreatedOnePricingPayload; +} + +/** + * Matcher function that matches a CreatedOnePricing while also inferring its type using TypeScript's type predicate + * feature. + */ +export function isCreatedOnePricingAction( + action: MonkAction, +): action is MonkCreatedOnePricingAction { + return action.type === MonkActionType.CREATED_ONE_PRICING; +} + +/** + * Reducer function for a createdOnePricing action. + */ +export function createdOnePricing( + state: MonkState, + action: MonkCreatedOnePricingAction, +): MonkState { + const { pricings, inspections } = state; + const { payload } = action; + + const inspection = inspections.find((value) => value.id === payload.pricing.inspectionId); + if (inspection) { + inspection.pricings?.push(action.payload.pricing.id); + } + pricings.push(action.payload.pricing); + return { + ...state, + pricings: [...pricings], + inspections: [...inspections], + }; +} diff --git a/packages/common/src/state/actions/deletedOnePricing.ts b/packages/common/src/state/actions/deletedOnePricing.ts new file mode 100644 index 000000000..d2be9e5f2 --- /dev/null +++ b/packages/common/src/state/actions/deletedOnePricing.ts @@ -0,0 +1,64 @@ +import { MonkAction, MonkActionType } from './monkAction'; +import { MonkState } from '../state'; + +/** + * The payload of a MonkDeletedOnePricingPayload. + */ +export interface MonkDeletedtedOnePricingPayload { + /** + * The ID of the inspection to which the pricing was deleted. + */ + inspectionId: string; + /** + * The pricing ID deleted. + */ + pricingId: string; +} + +/** + * Action dispatched when a pricing have been deleted. + */ +export interface MonkDeletedOnePricingAction extends MonkAction { + /** + * The type of the action : `MonkActionType.DELETED_ONE_PRICING`. + */ + type: MonkActionType.DELETED_ONE_PRICING; + /** + * The payload of the action containing the fetched entities. + */ + payload: MonkDeletedtedOnePricingPayload; +} + +/** + * Matcher function that matches a DeletedOnePricing while also inferring its type using TypeScript's type predicate + * feature. + */ +export function isDeletedOnePricingAction( + action: MonkAction, +): action is MonkDeletedOnePricingAction { + return action.type === MonkActionType.DELETED_ONE_PRICING; +} + +/** + * Reducer function for a deletedOnePricing action. + */ +export function deletedOnePricing( + state: MonkState, + action: MonkDeletedOnePricingAction, +): MonkState { + const { pricings, inspections } = state; + const { payload } = action; + + const inspection = inspections.find((value) => value.id === payload.inspectionId); + if (inspection) { + inspection.pricings = inspection.pricings?.filter( + (pricingId) => pricingId !== payload.pricingId, + ); + } + const newPricings = pricings.filter((pricing) => pricing.id !== payload.pricingId); + return { + ...state, + pricings: newPricings, + inspections: [...inspections], + }; +} diff --git a/packages/common/src/state/actions/index.ts b/packages/common/src/state/actions/index.ts index eb8f83e06..496420e68 100644 --- a/packages/common/src/state/actions/index.ts +++ b/packages/common/src/state/actions/index.ts @@ -4,3 +4,7 @@ export * from './gotOneInspection'; export * from './createdOneImage'; export * from './updatedManyTasks'; export * from './updatedVehicle'; +export * from './createdOnePricing'; +export * from './deletedOnePricing'; +export * from './updatedOnePricing'; +export * from './updatedOneInspectionAdditionalData'; diff --git a/packages/common/src/state/actions/monkAction.ts b/packages/common/src/state/actions/monkAction.ts index 33fc16d41..53ad2625c 100644 --- a/packages/common/src/state/actions/monkAction.ts +++ b/packages/common/src/state/actions/monkAction.ts @@ -6,6 +6,10 @@ export enum MonkActionType { * An inspection has been fetched from the API. */ GOT_ONE_INSPECTION = 'got_one_inspection', + /** + * An inspection additional data has been updated. + */ + UPDATED_ONE_INSPECTION_ADDITIONAL_DATA = 'updated_one_inspection_additional_data', /** * An image has been uploaded to the API. */ @@ -14,14 +18,26 @@ export enum MonkActionType { * One or more tasks have been updated. */ UPDATED_MANY_TASKS = 'updated_many_tasks', - /** - * Clear and reset the state. - */ - RESET_STATE = 'reset_state', /** * A vehicle has been updated. */ UPDATED_VEHICLE = 'updated_vehicle', + /** + * A pricing has been uploaded to the API. + */ + CREATED_ONE_PRICING = 'created_one_pricing', + /** + * A pricing has been updated. + */ + UPDATED_ONE_PRICING = 'updated_one_pricing', + /** + * A pricing has been deleted. + */ + DELETED_ONE_PRICING = 'deleted_one_pricing', + /** + * Clear and reset the state. + */ + RESET_STATE = 'reset_state', } /** diff --git a/packages/common/src/state/actions/updatedOneInspectionAdditionalData.ts b/packages/common/src/state/actions/updatedOneInspectionAdditionalData.ts new file mode 100644 index 000000000..a96d30ce4 --- /dev/null +++ b/packages/common/src/state/actions/updatedOneInspectionAdditionalData.ts @@ -0,0 +1,61 @@ +import { AdditionalData } from '@monkvision/types'; +import { MonkAction, MonkActionType } from './monkAction'; +import { MonkState } from '../state'; + +/** + * The payload of a MonkUpdatedOneInspectionAdditionalDataPayload. + */ +export interface MonkUpdatedOneInspectionAdditionalDataPayload { + /** + * The ID of the inspection to which the pricing was updated. + */ + inspectionId: string; + /** + * Additional data used for the update operation. + */ + additionalData?: AdditionalData; +} + +/** + * Action dispatched when a inspection have been updated. + */ +export interface MonkUpdatedOneInspectionAdditionalDataAction extends MonkAction { + /** + * The type of the action : `MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA`. + */ + type: MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA; + /** + * The payload of the action containing the fetched entities. + */ + payload: MonkUpdatedOneInspectionAdditionalDataPayload; +} + +/** + * Matcher function that matches a UpdatedOneInspection while also inferring its type using TypeScript's type predicate + * feature. + */ +export function isUpdatedOneInspectionAdditionalDataAction( + action: MonkAction, +): action is MonkUpdatedOneInspectionAdditionalDataAction { + return action.type === MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA; +} + +/** + * Reducer function for a UpdatedOneInspection action. + */ +export function updatedOneInspectionAdditionalData( + state: MonkState, + action: MonkUpdatedOneInspectionAdditionalDataAction, +): MonkState { + const { inspections } = state; + const { payload } = action; + + const inspection = inspections.find((value) => value.id === payload.inspectionId); + if (inspection) { + inspection.additionalData = payload.additionalData; + } + return { + ...state, + inspections: [...inspections], + }; +} diff --git a/packages/common/src/state/actions/updatedOnePricing.ts b/packages/common/src/state/actions/updatedOnePricing.ts new file mode 100644 index 000000000..e4a4457b0 --- /dev/null +++ b/packages/common/src/state/actions/updatedOnePricing.ts @@ -0,0 +1,56 @@ +import { PricingV2Details } from '@monkvision/types'; +import { MonkAction, MonkActionType } from './monkAction'; +import { MonkState } from '../state'; + +/** + * The payload of a MonkUpdatedOnePricingPayload. + */ +export interface MonkUpdatedOnePricingPayload { + /** + * The pricing created. + */ + pricing: PricingV2Details; +} + +/** + * Action dispatched when a pricing have been updated. + */ +export interface MonkUpdatedOnePricingAction extends MonkAction { + /** + * The type of the action : `MonkActionType.UPDATED_ONE_PRICING`. + */ + type: MonkActionType.UPDATED_ONE_PRICING; + /** + * The payload of the action containing the fetched entities. + */ + payload: MonkUpdatedOnePricingPayload; +} + +/** + * Matcher function that matches a updatedOnePricing while also inferring its type using TypeScript's type predicate + * feature. + */ +export function isUpdatedOnePricingAction( + action: MonkAction, +): action is MonkUpdatedOnePricingAction { + return action.type === MonkActionType.UPDATED_ONE_PRICING; +} + +/** + * Reducer function for a updatedOnePricing action. + */ +export function updatedOnePricing( + state: MonkState, + action: MonkUpdatedOnePricingAction, +): MonkState { + const { pricings } = state; + const { payload } = action; + + const updatedPricings = pricings.map((pricing) => + pricing.id === payload.pricing.id ? { ...pricing, ...payload.pricing } : pricing, + ); + return { + ...state, + pricings: updatedPricings, + }; +} diff --git a/packages/common/src/state/reducer.ts b/packages/common/src/state/reducer.ts index d8ad50b23..713b6bd7b 100644 --- a/packages/common/src/state/reducer.ts +++ b/packages/common/src/state/reducer.ts @@ -5,9 +5,19 @@ import { isGotOneInspectionAction, isResetStateAction, isUpdatedManyTasksAction, + isCreatedOnePricingAction, + isDeletedOnePricingAction, + isUpdatedOnePricingAction, + isUpdatedOneInspectionAdditionalDataAction, + isUpdatedVehicleAction, MonkAction, resetState, updatedManyTasks, + createdOnePricing, + deletedOnePricing, + updatedOnePricing, + updatedOneInspectionAdditionalData, + updatedVehicle, } from './actions'; import { MonkState } from './state'; @@ -21,11 +31,26 @@ export function monkReducer(state: MonkState, action: MonkAction): MonkState { if (isGotOneInspectionAction(action)) { return gotOneInspection(state, action); } + if (isUpdatedOneInspectionAdditionalDataAction(action)) { + return updatedOneInspectionAdditionalData(state, action); + } if (isCreatedOneImageAction(action)) { return createdOneImage(state, action); } if (isUpdatedManyTasksAction(action)) { return updatedManyTasks(state, action); } + if (isCreatedOnePricingAction(action)) { + return createdOnePricing(state, action); + } + if (isDeletedOnePricingAction(action)) { + return deletedOnePricing(state, action); + } + if (isUpdatedOnePricingAction(action)) { + return updatedOnePricing(state, action); + } + if (isUpdatedVehicleAction(action)) { + return updatedVehicle(state, action); + } return state; } diff --git a/packages/common/src/state/state.ts b/packages/common/src/state/state.ts index 6db82f8cd..0a11f9d36 100644 --- a/packages/common/src/state/state.ts +++ b/packages/common/src/state/state.ts @@ -4,6 +4,7 @@ import { Inspection, Part, PartOperation, + PricingV2Details, RenderedOutput, SeverityResult, Task, @@ -55,6 +56,10 @@ export interface MonkState { * The views created during inspections. */ views: View[]; + /** + * The pricings created during inspections. + */ + pricings: PricingV2Details[]; } /** @@ -72,5 +77,6 @@ export function createEmptyMonkState(): MonkState { tasks: [], vehicles: [], views: [], + pricings: [], }; } diff --git a/packages/common/test/state/actions/createdOnePricing.test.ts b/packages/common/test/state/actions/createdOnePricing.test.ts new file mode 100644 index 000000000..abf0a867b --- /dev/null +++ b/packages/common/test/state/actions/createdOnePricing.test.ts @@ -0,0 +1,57 @@ +import { + createEmptyMonkState, + MonkActionType, + createdOnePricing, + MonkCreatedOnePricingAction, + isCreatedOnePricingAction, +} from '../../../src'; +import { Inspection, MonkEntityType, PricingV2RelatedItemType } from '@monkvision/types'; + +const action: MonkCreatedOnePricingAction = { + type: MonkActionType.CREATED_ONE_PRICING, + payload: { + pricing: { + entityType: MonkEntityType.PRICING, + id: 'test-id', + inspectionId: 'inspections-test', + relatedItemType: PricingV2RelatedItemType.PART, + pricing: 10, + }, + }, +}; + +describe('CreatedOnePricing action handlers', () => { + describe('Action matcher', () => { + it('should return true if the action has the proper type', () => { + expect(isCreatedOnePricingAction({ type: MonkActionType.CREATED_ONE_PRICING })).toBe(true); + }); + + it('should return false if the action does not have the proper type', () => { + expect(isCreatedOnePricingAction({ type: MonkActionType.RESET_STATE })).toBe(false); + }); + }); + + describe('Action handler', () => { + it('should return a new state', () => { + const state = createEmptyMonkState(); + expect(Object.is(createdOnePricing(state, action), state)).toBe(false); + }); + + it('should create pricing in the state', () => { + const state = createEmptyMonkState(); + state.inspections.push({ + id: 'inspections-test', + pricings: [] as string[], + } as Inspection); + const newState = createdOnePricing(state, action); + const inspectionPricing = newState.inspections.find( + (ins) => ins.id === action.payload.pricing.inspectionId, + )?.pricings; + expect(inspectionPricing?.length).toBe(1); + expect(inspectionPricing).toContainEqual(action.payload.pricing.id); + expect(newState.pricings).toContainEqual({ + ...action.payload.pricing, + }); + }); + }); +}); diff --git a/packages/common/test/state/actions/deletedOnePricing.test.ts b/packages/common/test/state/actions/deletedOnePricing.test.ts new file mode 100644 index 000000000..5f3533621 --- /dev/null +++ b/packages/common/test/state/actions/deletedOnePricing.test.ts @@ -0,0 +1,53 @@ +import { + createEmptyMonkState, + MonkActionType, + MonkDeletedOnePricingAction, + isDeletedOnePricingAction, + deletedOnePricing, +} from '../../../src'; +import { Inspection, PricingV2Details } from '@monkvision/types'; + +const action: MonkDeletedOnePricingAction = { + type: MonkActionType.DELETED_ONE_PRICING, + payload: { + inspectionId: 'inspections-test', + pricingId: 'pricing-id-test', + }, +}; + +describe('DeletedOnePricing action handlers', () => { + describe('Action matcher', () => { + it('should return true if the action has the proper type', () => { + expect(isDeletedOnePricingAction({ type: MonkActionType.DELETED_ONE_PRICING })).toBe(true); + }); + + it('should return false if the action does not have the proper type', () => { + expect(isDeletedOnePricingAction({ type: MonkActionType.RESET_STATE })).toBe(false); + }); + }); + + describe('Action handler', () => { + it('should return a new state', () => { + const state = createEmptyMonkState(); + expect(Object.is(deletedOnePricing(state, action), state)).toBe(false); + }); + + it('should delete pricing in the state', () => { + const state = createEmptyMonkState(); + state.inspections.push({ + id: 'inspections-test', + pricings: [action.payload.pricingId], + } as Inspection); + state.pricings.push({ id: action.payload.pricingId } as PricingV2Details); + const newState = deletedOnePricing(state, action); + const inspectionPricing = newState.inspections.find( + (ins) => ins.id === action.payload.inspectionId, + )?.pricings; + expect(inspectionPricing?.length).toBe(0); + expect(inspectionPricing).not.toContainEqual(action.payload.pricingId); + expect( + newState.pricings.find((pricing) => pricing.id === action.payload.pricingId), + ).toBeUndefined(); + }); + }); +}); diff --git a/packages/common/test/state/actions/gotOneInspection.test.ts b/packages/common/test/state/actions/gotOneInspection.test.ts index 83d67fe31..3c2c87062 100644 --- a/packages/common/test/state/actions/gotOneInspection.test.ts +++ b/packages/common/test/state/actions/gotOneInspection.test.ts @@ -13,6 +13,8 @@ import { Inspection, Part, PartOperation, + PricingV2Details, + PricingV2RelatedItemType, RenderedOutput, SeverityResult, Task, @@ -34,6 +36,7 @@ const action: MonkGotOneInspectionAction = { tasks: [{ id: 'tasks-test' } as Task], vehicles: [{ id: 'vehicles-test' } as Vehicle], views: [{ id: 'views-test' } as View], + pricings: [{ id: 'pricings-test' } as PricingV2Details], }, }; @@ -66,6 +69,7 @@ describe('GotOneInspection action handlers', () => { tasks: [{ id: 'tasks-test-111111' } as Task], vehicles: [{ id: 'vehicles-test-111111' } as Vehicle], views: [{ id: 'views-test-111111' } as View], + pricings: [{ id: 'pricings-test-111111' } as PricingV2Details], }; const newState = gotOneInspection(state, action); Object.keys(createEmptyMonkState()).forEach((key) => { @@ -87,6 +91,12 @@ describe('GotOneInspection action handlers', () => { tasks: [{ id: 'tasks-test', images: ['ok'] } as Task], vehicles: [{ id: 'vehicles-test', type: 'nice' } as Vehicle], views: [{ id: 'views-test', elementId: 'ww' } as View], + pricings: [ + { + id: 'pricings-test', + relatedItemType: PricingV2RelatedItemType.PART, + } as PricingV2Details, + ], }; const newState = gotOneInspection(state, action); Object.keys(createEmptyMonkState()).forEach((key) => { diff --git a/packages/common/test/state/actions/updatedOneInspectionAdditionalData.test.ts b/packages/common/test/state/actions/updatedOneInspectionAdditionalData.test.ts new file mode 100644 index 000000000..fd4faf5b8 --- /dev/null +++ b/packages/common/test/state/actions/updatedOneInspectionAdditionalData.test.ts @@ -0,0 +1,52 @@ +import { + createEmptyMonkState, + MonkActionType, + MonkUpdatedOneInspectionAdditionalDataAction, + isUpdatedOneInspectionAdditionalDataAction, + updatedOneInspectionAdditionalData, +} from '../../../src'; +import { Inspection } from '@monkvision/types'; + +const action: MonkUpdatedOneInspectionAdditionalDataAction = { + type: MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA, + payload: { + inspectionId: 'inspections-test', + additionalData: { 'add-data-test': 'additionalData-test' }, + }, +}; + +describe('UpdatedOne action handlers', () => { + describe('Action matcher', () => { + it('should return true if the action has the proper type', () => { + expect( + isUpdatedOneInspectionAdditionalDataAction({ + type: MonkActionType.UPDATED_ONE_INSPECTION_ADDITIONAL_DATA, + }), + ).toBe(true); + }); + + it('should return false if the action does not have the proper type', () => { + expect(isUpdatedOneInspectionAdditionalDataAction({ type: MonkActionType.RESET_STATE })).toBe( + false, + ); + }); + }); + + describe('Action handler', () => { + it('should return a new state', () => { + const state = createEmptyMonkState(); + expect(Object.is(updatedOneInspectionAdditionalData(state, action), state)).toBe(false); + }); + + it('should update pricing in the state', () => { + const state = createEmptyMonkState(); + state.inspections.push({ + id: 'inspections-test', + additionalData: {}, + } as Inspection); + const newState = updatedOneInspectionAdditionalData(state, action); + const inspection = newState.inspections.find((ins) => ins.id === action.payload.inspectionId); + expect(inspection?.additionalData).toEqual(action.payload.additionalData); + }); + }); +}); diff --git a/packages/common/test/state/actions/updatedOnePricing.test.ts b/packages/common/test/state/actions/updatedOnePricing.test.ts new file mode 100644 index 000000000..e084427f6 --- /dev/null +++ b/packages/common/test/state/actions/updatedOnePricing.test.ts @@ -0,0 +1,58 @@ +import { + createEmptyMonkState, + MonkActionType, + MonkUpdatedOnePricingAction, + isUpdatedOnePricingAction, + updatedOnePricing, +} from '../../../src'; +import { Inspection, MonkEntityType, PricingV2RelatedItemType } from '@monkvision/types'; + +const action: MonkUpdatedOnePricingAction = { + type: MonkActionType.UPDATED_ONE_PRICING, + payload: { + pricing: { + entityType: MonkEntityType.PRICING, + id: 'test-id', + inspectionId: 'inspections-test', + relatedItemType: PricingV2RelatedItemType.PART, + pricing: 10, + }, + }, +}; + +describe('UpdatedOnePricing action handlers', () => { + describe('Action matcher', () => { + it('should return true if the action has the proper type', () => { + expect(isUpdatedOnePricingAction({ type: MonkActionType.UPDATED_ONE_PRICING })).toBe(true); + }); + + it('should return false if the action does not have the proper type', () => { + expect(isUpdatedOnePricingAction({ type: MonkActionType.RESET_STATE })).toBe(false); + }); + }); + + describe('Action handler', () => { + it('should return a new state', () => { + const state = createEmptyMonkState(); + expect(Object.is(updatedOnePricing(state, action), state)).toBe(false); + }); + + it('should update pricing in the state', () => { + const state = createEmptyMonkState(); + state.inspections.push({ + id: 'inspections-test', + pricings: [action.payload.pricing.id], + } as Inspection); + state.pricings.push({ ...action.payload.pricing, pricing: 90 }); + const newState = updatedOnePricing(state, action); + const inspectionPricing = newState.inspections.find( + (ins) => ins.id === action.payload.pricing.inspectionId, + )?.pricings; + expect(inspectionPricing?.length).toBe(1); + expect(inspectionPricing).toContainEqual(action.payload.pricing.id); + expect(newState.pricings).toContainEqual({ + ...action.payload.pricing, + }); + }); + }); +}); diff --git a/packages/common/test/state/reducer.test.ts b/packages/common/test/state/reducer.test.ts index 1441c8190..57c804fc8 100644 --- a/packages/common/test/state/reducer.test.ts +++ b/packages/common/test/state/reducer.test.ts @@ -3,19 +3,39 @@ jest.mock('../../src/state/actions', () => ({ isGotOneInspectionAction: jest.fn(() => false), isResetStateAction: jest.fn(() => false), isUpdatedManyTasksAction: jest.fn(() => false), + isCreatedOnePricingAction: jest.fn(() => false), + isDeletedOnePricingAction: jest.fn(() => false), + isUpdatedOnePricingAction: jest.fn(() => false), + isUpdatedOneInspectionAdditionalDataAction: jest.fn(() => false), + isUpdatedVehicleAction: jest.fn(() => false), createdOneImage: jest.fn(() => null), gotOneInspection: jest.fn(() => null), resetState: jest.fn(() => null), updatedManyTasks: jest.fn(() => null), + createdOnePricing: jest.fn(() => null), + deletedOnePricing: jest.fn(() => null), + updatedOnePricing: jest.fn(() => null), + updatedOneInspectionAdditionalData: jest.fn(() => null), + updatedVehicle: jest.fn(() => null), })); import { createdOneImage, gotOneInspection, + createdOnePricing, + deletedOnePricing, + updatedOnePricing, + updatedOneInspectionAdditionalData, + updatedVehicle, isCreatedOneImageAction, isGotOneInspectionAction, isResetStateAction, isUpdatedManyTasksAction, + isCreatedOnePricingAction, + isDeletedOnePricingAction, + isUpdatedOnePricingAction, + isUpdatedOneInspectionAdditionalDataAction, + isUpdatedVehicleAction, MonkAction, monkReducer, MonkState, @@ -28,6 +48,14 @@ const actions = [ { matcher: isGotOneInspectionAction, handler: gotOneInspection }, { matcher: isCreatedOneImageAction, handler: createdOneImage }, { matcher: isUpdatedManyTasksAction, handler: updatedManyTasks }, + { matcher: isCreatedOnePricingAction, handler: createdOnePricing }, + { matcher: isDeletedOnePricingAction, handler: deletedOnePricing }, + { matcher: isUpdatedOnePricingAction, handler: updatedOnePricing }, + { + matcher: isUpdatedOneInspectionAdditionalDataAction, + handler: updatedOneInspectionAdditionalData, + }, + { matcher: isUpdatedVehicleAction, handler: updatedVehicle }, ] as unknown as { matcher: jest.Mock; handler: jest.Mock; noParams?: boolean }[]; describe('Monk state reducer', () => { diff --git a/packages/types/src/state/entity.ts b/packages/types/src/state/entity.ts index 336bf8849..49215cb4b 100644 --- a/packages/types/src/state/entity.ts +++ b/packages/types/src/state/entity.ts @@ -13,6 +13,7 @@ export enum MonkEntityType { TASK = 'TASK', VEHICLE = 'VEHICLE', VIEW = 'VIEW', + PRICING = 'PRICING', } /** diff --git a/packages/types/src/state/inspection.ts b/packages/types/src/state/inspection.ts index cfe631149..94c5fc4fc 100644 --- a/packages/types/src/state/inspection.ts +++ b/packages/types/src/state/inspection.ts @@ -1,6 +1,5 @@ import { AdditionalData } from './common'; import { MonkEntity, MonkEntityType } from './entity'; -import { PricingV2 } from './pricingV2'; import { WheelAnalysis } from './wheelAnalysis'; /** @@ -44,7 +43,7 @@ export interface Inspection extends MonkEntity { /** * The details about the cost of the vehicle reparations using the PricingV2 API if it was requested. */ - pricing?: PricingV2; + pricings?: string[]; /** * Additional data added during the creation of the inspection. */ diff --git a/packages/types/src/state/pricingV2.ts b/packages/types/src/state/pricingV2.ts index 5946d8453..c656d150d 100644 --- a/packages/types/src/state/pricingV2.ts +++ b/packages/types/src/state/pricingV2.ts @@ -1,3 +1,5 @@ +import { MonkEntity } from './entity'; + /** * Enumeration of the types of items that a PricingV2 object can refer to. */ @@ -32,7 +34,7 @@ export enum RepairOperationType { * Details of the pricing using the expanded pricing feature. Provides details about the operations and the hours of * labour required and the cost of repairs for a specific part or on the entirety of the vehicle. */ -export interface PricingV2Details { +export interface PricingV2Details extends MonkEntity { /** * The ID of the inspection associated with this pricing information. */