add tests for API endpoint: user
This commit is contained in:
40
tests/APIUser.test.ts
Normal file
40
tests/APIUser.test.ts
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
|
import { GET } from '../src/routes/api/user/+server';
|
||||||
|
|
||||||
|
const id = 'admin';
|
||||||
|
|
||||||
|
describe('API-Endpoints: User ist Admin', () => {
|
||||||
|
test('User ist Admin', async () => {
|
||||||
|
const admin = true;
|
||||||
|
const event = {
|
||||||
|
locals: {
|
||||||
|
user: { id, admin }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fakeResult = { admin };
|
||||||
|
|
||||||
|
const response = await GET(event);
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
const json = await response.json();
|
||||||
|
expect(json).toEqual(fakeResult);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('User ist kein Admin', async () => {
|
||||||
|
const admin = false;
|
||||||
|
const event = {
|
||||||
|
locals: {
|
||||||
|
user: { id, admin }
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const fakeResult = { admin };
|
||||||
|
|
||||||
|
const response = await GET(event);
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
|
||||||
|
const json = await response.json();
|
||||||
|
expect(json).toEqual(fakeResult);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user