-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from maykinmedia/issue/permission-test
✨ - feat: permissions test
- Loading branch information
Showing
14 changed files
with
376 additions
and
86 deletions.
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
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 }; |
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,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]), | ||
); | ||
}; | ||
}; |
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 |
---|---|---|
@@ -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 }; |
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 |
---|---|---|
@@ -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 }; |
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 |
---|---|---|
@@ -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 }; |
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
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", | ||
|
@@ -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", | ||
|
@@ -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", | ||
|
@@ -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, | ||
}; |
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
Oops, something went wrong.