2022-09-09 22:46:53 +00:00
|
|
|
import { describe, test, expect } from "vitest";
|
2022-10-09 17:23:21 +00:00
|
|
|
import { factories } from "./factories";
|
2022-09-04 02:42:03 +00:00
|
|
|
|
2022-09-09 22:46:53 +00:00
|
|
|
describe("[GET] /api/v1/status", () => {
|
|
|
|
test("server should respond", async () => {
|
2022-10-09 17:23:21 +00:00
|
|
|
const api = factories.client.public();
|
2022-09-04 02:42:03 +00:00
|
|
|
const { response, data } = await api.status();
|
|
|
|
expect(response.status).toBe(200);
|
|
|
|
expect(data.health).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2022-10-07 02:54:09 +00:00
|
|
|
describe("first time user workflow (register, login, join group)", () => {
|
2022-10-09 17:23:21 +00:00
|
|
|
const api = factories.client.public();
|
|
|
|
const userData = factories.user();
|
2022-09-04 02:42:03 +00:00
|
|
|
|
2022-09-09 22:46:53 +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-09 22:46:53 +00:00
|
|
|
test("user should be able to login", async () => {
|
2022-09-27 23:52:13 +00:00
|
|
|
const { response, data } = await api.login(userData.email, userData.password);
|
2022-09-04 02:42:03 +00:00
|
|
|
expect(response.status).toBe(200);
|
|
|
|
expect(data.token).toBeTruthy();
|
|
|
|
|
|
|
|
// Cleanup
|
2022-10-09 17:23:21 +00:00
|
|
|
const userApi = factories.client.user(data.token);
|
2022-09-04 02:42:03 +00:00
|
|
|
{
|
2022-10-07 02:54:09 +00:00
|
|
|
const { response } = await userApi.user.delete();
|
2022-09-04 02:42:03 +00:00
|
|
|
expect(response.status).toBe(204);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|