-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7f3e910
commit 04279ec
Showing
23 changed files
with
374 additions
and
75 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
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
Binary file not shown.
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
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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { http, HttpResponse } from 'msw' | ||
import type { Privilege } from 'src/models' | ||
|
||
const datas: Privilege[] = [] | ||
|
||
for (let i = 0; i < 20; i++) { | ||
const data: Privilege = { | ||
id: i, | ||
name: 'privilege_' + i, | ||
superiorId: i, | ||
meta: { | ||
icon: 'user' | ||
}, | ||
enabled: i % 3 > 0, | ||
description: 'description', | ||
lastModifiedDate: new Date() | ||
} | ||
datas.push(data) | ||
} | ||
|
||
export const rolesHandlers = [ | ||
http.get('/api/privileges', ({ request }) => { | ||
const url = new URL(request.url) | ||
const page = url.searchParams.get('page') | ||
const size = url.searchParams.get('size') | ||
// Construct a JSON response with the list of all Dictionarys | ||
// as the response body. | ||
const data = { | ||
content: Array.from(datas.slice(Number(page) * Number(size), (Number(page) + 1) * Number(size))), | ||
totalElements: datas.length | ||
} | ||
|
||
return HttpResponse.json(data) | ||
}), | ||
http.post('/api/privileges', async ({ request }) => { | ||
// Read the intercepted request body as JSON. | ||
const newData = await request.json() as Privilege | ||
|
||
// Push the new Dictionary to the map of all Dictionarys. | ||
datas.push(newData) | ||
|
||
// Don't forget to declare a semantic "201 Created" | ||
// response and send back the newly created Dictionary! | ||
return HttpResponse.json(newData, { status: 201 }) | ||
}), | ||
http.delete('/api/privileges/:id', ({ params }) => { | ||
// All request path params are provided in the "params" | ||
// argument of the response resolver. | ||
const { id } = params | ||
|
||
// Let's attempt to grab the Dictionary by its ID. | ||
const deletedData = datas.filter(item => item.id === Number(id)) | ||
|
||
// Respond with a "404 Not Found" response if the given | ||
// Dictionary ID does not exist. | ||
if (!deletedData) { | ||
return new HttpResponse(null, { status: 404 }) | ||
} | ||
|
||
// Delete the Dictionary from the "allDictionarys" map. | ||
datas.pop() | ||
|
||
// Respond with a "200 OK" response and the deleted Dictionary. | ||
return HttpResponse.json(deletedData) | ||
}) | ||
] |
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
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
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
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.