Skip to content

Commit

Permalink
Merge pull request #185 from maykinmedia/issue/permission-test
Browse files Browse the repository at this point in the history
✨ - feat: permissions test
  • Loading branch information
Xaohs authored Jul 12, 2024
2 parents f1ec130 + 496337e commit 299a557
Show file tree
Hide file tree
Showing 14 changed files with 376 additions and 86 deletions.
17 changes: 12 additions & 5 deletions frontend/src/fixtures/destructionList.ts
Original file line number Diff line number Diff line change
@@ -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<DestructionList>(
FIXTURE_DESTRUCTION_LIST,
);

export { destructionListFactory };
25 changes: 25 additions & 0 deletions frontend/src/fixtures/factory.ts
Original file line number Diff line number Diff line change
@@ -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>) => T} - Function to create objects with specified properties
*/
export const createObjectFactory = <T>(defaultValues: T) => {
return (overrides: RecursivePartial<T> = {}): 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>[]) => T[]} - Function to create arrays of objects with specified properties
*/
export const createArrayFactory = <T>(defaultValues: T[]) => {
return (overrides: RecursivePartial<T>[] = []): T[] => {
return defaultValues.map((defaultItem, index) =>
Object.assign({}, defaultItem, overrides[index]),
);
};
};
14 changes: 11 additions & 3 deletions frontend/src/fixtures/paginatedZaken.ts
Original file line number Diff line number Diff line change
@@ -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<PaginatedZaken>(
FIXTURE_PAGINATED_ZAKEN,
);

export { paginatedZakenFactory };
15 changes: 10 additions & 5 deletions frontend/src/fixtures/review.ts
Original file line number Diff line number Diff line change
@@ -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<Review>(FIXTURE_REVIEW);

export { reviewFactory };
20 changes: 13 additions & 7 deletions frontend/src/fixtures/reviewItem.ts
Original file line number Diff line number Diff line change
@@ -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<ReviewItem>(FIXTURE_REVIEW_ITEM);
const reviewItemsFactory = createArrayFactory<ReviewItem>(FIXTURE_REVIEW_ITEMS);

export { reviewItemFactory, reviewItemsFactory };
13 changes: 10 additions & 3 deletions frontend/src/fixtures/selectieLijstKlasseChoices.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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<Option>(
FIXTURE_SELECTIELIJSTKLASSE_CHOICES,
);

export { FIXTURE_SELECTIELIJSTKLASSE_CHOICES_MAP, selectieLijstKlasseFactory };
44 changes: 38 additions & 6 deletions frontend/src/fixtures/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { User } from "../lib/api/auth";
import { createArrayFactory, createObjectFactory } from "./factory";

export const FIXTURE_RECORD_MANAGER: User = {
const FIXTURE_USER: User = {
pk: 1,
username: "testuser",
firstName: "Test",
lastName: "User",
email: "[email protected]",
role: {
name: "Test Role",
canStartDestruction: false,
canReviewDestruction: false,
canViewCaseDetails: true,
},
};

const FIXTURE_RECORD_MANAGER: User = {
pk: 1,
username: "Record Manager",
firstName: "Record",
Expand All @@ -14,7 +29,7 @@ export const FIXTURE_RECORD_MANAGER: User = {
},
};

export const FIXTURE_BEOORDELAAR: User = {
const FIXTURE_BEOORDELAAR: User = {
pk: 2,
username: "Beoor del Laar",
firstName: "Beoor",
Expand All @@ -28,7 +43,7 @@ export const FIXTURE_BEOORDELAAR: User = {
},
};

export const FIXTURE_PROCES_EIGENAAR: User = {
const FIXTURE_PROCES_EIGENAAR: User = {
pk: 3,
username: "Proces ei Genaar",
firstName: "Proces",
Expand All @@ -42,8 +57,25 @@ export const FIXTURE_PROCES_EIGENAAR: User = {
},
};

export const FIXTURE_USERS = [
FIXTURE_RECORD_MANAGER,
FIXTURE_BEOORDELAAR,
const userFactory = createObjectFactory<User>(FIXTURE_USER);
const recordManagerFactory = createObjectFactory<User>(FIXTURE_RECORD_MANAGER);
const beoordelaarFactory = createObjectFactory<User>(FIXTURE_BEOORDELAAR);
const procesEigenaarFactory = createObjectFactory<User>(
FIXTURE_PROCES_EIGENAAR,
);

const defaultUsers: User[] = [
recordManagerFactory(),
beoordelaarFactory(),
procesEigenaarFactory(),
];

const usersFactory = createArrayFactory(defaultUsers);

export {
beoordelaarFactory,
procesEigenaarFactory,
recordManagerFactory,
userFactory,
usersFactory,
};
10 changes: 8 additions & 2 deletions frontend/src/fixtures/zaak.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Zaak } from "../types";
import { createArrayFactory, createObjectFactory } from "./factory";

export const FIXTURE_ZAAK: Zaak = {
const FIXTURE_ZAAK: Zaak = {
uuid: "87691e74-1b0b-491a-aa63-0a396bbb1e3e",
url: "http://localhost:8000/zaken/api/v1/zaken/87691e74-1b0b-491a-aa63-0a396bbb1e3e",
rollen: [],
Expand Down Expand Up @@ -56,7 +57,7 @@ export const FIXTURE_ZAAK: Zaak = {
verantwoordelijkeOrganisatie: "104567387",
} as Zaak;

export const FIXTURE_ZAKEN: Zaak[] = [
const FIXTURE_ZAKEN: Zaak[] = [
FIXTURE_ZAAK,
{
uuid: "3038cc8e-003b-411c-b6ef-7dc5ddc5a3ee",
Expand Down Expand Up @@ -541,3 +542,8 @@ export const FIXTURE_ZAKEN: Zaak[] = [
verantwoordelijkeOrganisatie: "104567387",
},
] as Zaak[];

const zaakFactory = createObjectFactory<Zaak>(FIXTURE_ZAAK);
const zakenFactory = createArrayFactory<Zaak>(FIXTURE_ZAKEN);

export { zaakFactory, zakenFactory };
19 changes: 12 additions & 7 deletions frontend/src/lib/api/destructionLists.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ export type DestructionList = {
uuid: string;
};

export type DestructionListStatus =
| "ready_to_review"
| "changes_requested"
| "ready_to_delete"
| "deleted"
| "ready_for_archivist"
| "internally_reviewed";
// An array to be used in various parts of the application.
export const DESTRUCTION_LIST_STATUSES = [
"ready_to_review",
"changes_requested",
"ready_to_delete",
"deleted",
"ready_for_archivist",
"internally_reviewed",
] as const;

// Inferring the type of the array, so that we don't have to repeat the same.
export type DestructionListStatus = (typeof DESTRUCTION_LIST_STATUSES)[number];

export type DestructionListAssignee = {
user: User;
Expand Down
Loading

0 comments on commit 299a557

Please sign in to comment.