homebox/frontend/lib/api/__test__/public.test.ts

42 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-09-05 00:37:37 +00:00
import { describe, test, expect } from 'vitest';
import { client, userClient } from './test-utils';
2022-09-04 02:42:03 +00:00
describe('[GET] /api/v1/status', () => {
2022-09-05 00:37:37 +00:00
test('server should respond', async () => {
2022-09-04 02:42:03 +00:00
const api = client();
const { response, data } = await api.status();
expect(response.status).toBe(200);
expect(data.health).toBe(true);
});
});
describe('first time user workflow (register, login)', () => {
const api = client();
const userData = {
groupName: 'test-group',
user: {
email: 'test-user@email.com',
name: 'test-user',
password: 'test-password',
},
};
2022-09-05 00:37:37 +00:00
test('user should be able to register', async () => {
2022-09-04 02:42:03 +00:00
const { response } = await api.register(userData);
expect(response.status).toBe(204);
});
2022-09-05 00:37:37 +00:00
test('user should be able to login', async () => {
2022-09-04 02:42:03 +00:00
const { response, data } = await api.login(userData.user.email, userData.user.password);
expect(response.status).toBe(200);
expect(data.token).toBeTruthy();
// Cleanup
const userApi = userClient(data.token);
{
const { response } = await userApi.deleteAccount();
expect(response.status).toBe(204);
}
});
});