diff --git a/frontend/src/fixtures/destructionList.ts b/frontend/src/fixtures/destructionList.ts index d90e4c473..41c045d49 100644 --- a/frontend/src/fixtures/destructionList.ts +++ b/frontend/src/fixtures/destructionList.ts @@ -1,15 +1,22 @@ import { DestructionList } from "../lib/api/destructionLists"; -import { FIXTURE_USERS } from "./user"; +import { createObjectFactory } from "./factory"; +import { userFactory, usersFactory } from "./user"; -export const FIXTURE_DESTRUCTION_LIST: DestructionList = { +const FIXTURE_DESTRUCTION_LIST: DestructionList = { pk: 1, uuid: "00000000-0000-0000-0000-000000000000", name: "My First Destruction List", - author: FIXTURE_USERS[0], + author: userFactory(), containsSensitiveInfo: false, status: "changes_requested", - assignees: FIXTURE_USERS.map((u, i) => ({ user: u, order: i })), - assignee: FIXTURE_USERS[0], + assignees: usersFactory().map((u, i) => ({ user: u, order: i })), + assignee: userFactory(), created: "2024-07-11T16:57", statusChanged: "2024-07-11:16:57", }; + +const destructionListFactory = createObjectFactory( + FIXTURE_DESTRUCTION_LIST, +); + +export { destructionListFactory }; diff --git a/frontend/src/fixtures/factory.ts b/frontend/src/fixtures/factory.ts new file mode 100644 index 000000000..7634bd9c1 --- /dev/null +++ b/frontend/src/fixtures/factory.ts @@ -0,0 +1,25 @@ +import { RecursivePartial } from "../lib/types/utilities"; + +/** + * Generic factory function to create individual objects with default and overridden properties + * @param {T} defaultValues - Default values for the object + * @returns {(overrides?: RecursivePartial) => T} - Function to create objects with specified properties + */ +export const createObjectFactory = (defaultValues: T) => { + return (overrides: RecursivePartial = {}): T => { + return Object.assign({}, defaultValues, overrides); + }; +}; + +/** + * Generic factory function to create arrays of objects with default and overridden properties + * @param {T[]} defaultValues - Default values for the array of objects + * @returns {(overrides?: RecursivePartial[]) => T[]} - Function to create arrays of objects with specified properties + */ +export const createArrayFactory = (defaultValues: T[]) => { + return (overrides: RecursivePartial[] = []): T[] => { + return defaultValues.map((defaultItem, index) => + Object.assign({}, defaultItem, overrides[index]), + ); + }; +}; diff --git a/frontend/src/fixtures/paginatedZaken.ts b/frontend/src/fixtures/paginatedZaken.ts index b73d4196c..2b99bb9cb 100644 --- a/frontend/src/fixtures/paginatedZaken.ts +++ b/frontend/src/fixtures/paginatedZaken.ts @@ -1,8 +1,16 @@ -import { FIXTURE_ZAKEN } from "./zaak"; +import { PaginatedZaken } from "../lib/api/zaken"; +import { createObjectFactory } from "./factory"; +import { zakenFactory } from "./zaak"; -export const FIXTURE_PAGINATED_ZAKEN = { +const FIXTURE_PAGINATED_ZAKEN = { count: 10, next: null, previous: null, - results: FIXTURE_ZAKEN, + results: zakenFactory(), }; + +const paginatedZakenFactory = createObjectFactory( + FIXTURE_PAGINATED_ZAKEN, +); + +export { paginatedZakenFactory }; diff --git a/frontend/src/fixtures/review.ts b/frontend/src/fixtures/review.ts index b8d8ad202..44ef6c073 100644 --- a/frontend/src/fixtures/review.ts +++ b/frontend/src/fixtures/review.ts @@ -1,12 +1,17 @@ import { Review } from "../lib/api/review"; -import { FIXTURE_DESTRUCTION_LIST } from "./destructionList"; -import { FIXTURE_BEOORDELAAR } from "./user"; +import { destructionListFactory } from "./destructionList"; +import { createObjectFactory } from "./factory"; +import { beoordelaarFactory } from "./user"; -export const FIXTURE_REVIEW: Review = { +const FIXTURE_REVIEW: Review = { pk: 1, - destructionList: FIXTURE_DESTRUCTION_LIST.uuid, - author: FIXTURE_BEOORDELAAR, + destructionList: destructionListFactory().uuid, + author: beoordelaarFactory(), decision: "rejected", listFeedback: "", created: "2024-06-24T17:08:10.474973+02:00", }; + +const reviewFactory = createObjectFactory(FIXTURE_REVIEW); + +export { reviewFactory }; diff --git a/frontend/src/fixtures/reviewItem.ts b/frontend/src/fixtures/reviewItem.ts index d5e04c3d6..71fedca51 100644 --- a/frontend/src/fixtures/reviewItem.ts +++ b/frontend/src/fixtures/reviewItem.ts @@ -1,22 +1,28 @@ -import { Review, ReviewItem } from "../lib/api/review"; -import { FIXTURE_ZAAK, FIXTURE_ZAKEN } from "./zaak"; +import { ReviewItem } from "../lib/api/review"; +import { createArrayFactory, createObjectFactory } from "./factory"; +import { zaakFactory, zakenFactory } from "./zaak"; -export const FIXTURE_REVIEW_ITEM: ReviewItem = { +const FIXTURE_REVIEW_ITEM: ReviewItem = { pk: 1, - zaak: FIXTURE_ZAAK, + zaak: zaakFactory(), feedback: "Deze niet", }; -export const FIXTURE_REVIEW_ITEMS: ReviewItem[] = [ +const FIXTURE_REVIEW_ITEMS: ReviewItem[] = [ FIXTURE_REVIEW_ITEM, { pk: 2, - zaak: FIXTURE_ZAKEN[1], + zaak: zakenFactory()[1], feedback: "Deze ook niet", }, { pk: 3, - zaak: FIXTURE_ZAKEN[2], + zaak: zakenFactory()[2], feedback: "Deze nog niet", }, ]; + +const reviewItemFactory = createObjectFactory(FIXTURE_REVIEW_ITEM); +const reviewItemsFactory = createArrayFactory(FIXTURE_REVIEW_ITEMS); + +export { reviewItemFactory, reviewItemsFactory }; diff --git a/frontend/src/fixtures/selectieLijstKlasseChoices.ts b/frontend/src/fixtures/selectieLijstKlasseChoices.ts index f0043dc96..17d879077 100644 --- a/frontend/src/fixtures/selectieLijstKlasseChoices.ts +++ b/frontend/src/fixtures/selectieLijstKlasseChoices.ts @@ -1,8 +1,9 @@ import { Option } from "@maykin-ui/admin-ui"; -import { FIXTURE_ZAKEN } from "./zaak"; +import { createArrayFactory } from "./factory"; +import { zakenFactory } from "./zaak"; -export const FIXTURE_SELECTIELIJSTKLASSE_CHOICES: Option[] = [ +const FIXTURE_SELECTIELIJSTKLASSE_CHOICES: Option[] = [ { label: "1.1 - Ingericht - vernietigen - P10Y", value: @@ -45,10 +46,16 @@ export const FIXTURE_SELECTIELIJSTKLASSE_CHOICES: Option[] = [ }, ]; -export const FIXTURE_SELECTIELIJSTKLASSE_CHOICES_MAP = FIXTURE_ZAKEN.reduce( +const FIXTURE_SELECTIELIJSTKLASSE_CHOICES_MAP = zakenFactory().reduce( (acc, val) => ({ ...acc, [val.url as string]: FIXTURE_SELECTIELIJSTKLASSE_CHOICES, }), {}, ); + +const selectieLijstKlasseFactory = createArrayFactory