From c222d75ac516378b26eb5199fc246827873baf1b Mon Sep 17 00:00:00 2001 From: Chi Cong Tran Date: Tue, 2 Sep 2025 11:10:07 +0200 Subject: [PATCH] add tests for API endpoint: user --- tests/APIUser.test.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 tests/APIUser.test.ts diff --git a/tests/APIUser.test.ts b/tests/APIUser.test.ts new file mode 100644 index 0000000..352d13c --- /dev/null +++ b/tests/APIUser.test.ts @@ -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); + }); +});