Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 35 additions & 20 deletions tests/integrations/api/v1/migrations/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,45 @@ import { beforeAll, describe, expect } from '@jest/globals';
import { resetDatabase } from '../../../../setup';

describe('GET /api/v1/migrations', () => {
let response: Response;
let body: unknown;

beforeAll(async () => {
await resetDatabase();

response = await fetch('http://localhost:3000/api/v1/migrations');
body = await response.json();
});

it('should return status 201', () => {
expect(response.status).toEqual(201);
});

it('body should be an array greater than 0', () => {
expect(Array.isArray(body)).toBeTruthy();
expect((body as []).length).toBeGreaterThan(0);
});

it('database should have a table named `pgmigrations` with NO migrations ran', async () => {
const { rows: migrations } = await database.query({
text: 'SELECT * FROM pgmigrations',
describe('Anonymous user', () => {
describe('running pending migrations', () => {
it('for the first time', async () => {
const response = await fetch(
'http://localhost:3000/api/v1/migrations',
{ method: 'GET' }
);
const body = await response.json();

expect(response.status).toEqual(201);

expect(Array.isArray(body)).toBeTruthy();
expect((body as []).length).toBeGreaterThan(0);
});

it('retrieaving migrations list from database', async () => {
const { rows: migrations } = await database.query(
'SELECT * FROM pgmigrations'
);

expect(migrations).toHaveLength(0);
});

it('when migrations are already ran before', async () => {
const response = await fetch(
'http://localhost:3000/api/v1/migrations',
{ method: 'GET' }
);
const body = await response.json();

expect(response.status).toEqual(201);

expect(Array.isArray(body)).toBeTruthy();
expect((body as []).length).toBeGreaterThan(0);
});
});

expect(migrations).toHaveLength(0);
});
});
58 changes: 35 additions & 23 deletions tests/integrations/api/v1/migrations/post.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,44 @@ import { beforeAll, describe, expect } from '@jest/globals';
import { resetDatabase } from '../../../../setup';

describe('POST /api/v1/migrations', () => {
let response: Response;
let body: unknown;

beforeAll(async () => {
await resetDatabase();

response = await fetch('http://localhost:3000/api/v1/migrations', {
method: 'POST',
});
body = await response.json();
});

it('should return status 201', () => {
expect(response.status).toEqual(201);
});

it('body should be an array greater than 0', () => {
expect(Array.isArray(body)).toBeTruthy();
expect((body as []).length).toBeGreaterThan(0);
});

it('database should have a table named `pgmigrations` with at least one migration', async () => {
const { rows: migrations } = await database.query(
'SELECT * FROM pgmigrations'
);

expect(migrations.length).toBeGreaterThan(0);
describe('Anonymous user', () => {
describe('running pending migrations', () => {
it('for the first time', async () => {
const response = await fetch(
'http://localhost:3000/api/v1/migrations',
{ method: 'POST' }
);
const body = await response.json();

expect(response.status).toEqual(201);

expect(Array.isArray(body)).toBeTruthy();
expect((body as []).length).toBeGreaterThan(0);
});

it('retrieaving migrations list from database', async () => {
const { rows: migrations } = await database.query(
'SELECT * FROM pgmigrations'
);

expect(migrations.length).toBeGreaterThan(0);
});

it('when migrations are already ran before', async () => {
const response = await fetch(
'http://localhost:3000/api/v1/migrations',
{ method: 'POST' }
);
const body = await response.json();

expect(response.status).toEqual(200);
expect(Array.isArray(body)).toBeTruthy();
expect(body as []).toHaveLength(0);
});
});
});
});
65 changes: 22 additions & 43 deletions tests/integrations/api/v1/status/get.test.ts
Original file line number Diff line number Diff line change
@@ -1,55 +1,34 @@
import { beforeAll, describe, expect } from '@jest/globals';
import { DatabaseStatusResponse, StatusResponse } from '@v1/status';
import { describe, expect } from '@jest/globals';

describe('GET /api/v1/status', () => {
let response: Response;
let body: StatusResponse;
describe('Anonymous User', () => {
it('Retrieving current status', async () => {
const response = await fetch('http://localhost:3000/api/v1/status');
const body = await response.json();

beforeAll(async () => {
response = await fetch('http://localhost:3000/api/v1/status');
body = await response.json();
});

it('should return status 200', () => {
expect(response.status).toEqual(200);
});
expect(response.status).toEqual(200);

it('should return valid updated_at as ISO string', () => {
expect(body.updated_at).toBeDefined();

const parsedUpdatedAt = new Date(body.updated_at).toISOString();
expect(parsedUpdatedAt).toEqual(body.updated_at);
});
});
expect(body.updated_at).toBeDefined();

describe('GET /api/v1/status database', () => {
let response: Response;
let database: DatabaseStatusResponse;
const parsedUpdatedAt = new Date(body.updated_at).toISOString();
expect(parsedUpdatedAt).toEqual(body.updated_at);

beforeAll(async () => {
response = await fetch('http://localhost:3000/api/v1/status');
database = (await response.json()).database;
});
// Database
const database = body.database;

it('database status should be healtly', () => {
expect(database.status).toBeDefined();
expect(database.status).toEqual('helthly');
});
expect(database.status).toBeDefined();
expect(database.status).toEqual('helthly');

it('should return a valid current database version', () => {
expect(database.version).toBeDefined();
expect(typeof database.version).toBe('string');
expect(database.version).toEqual('16.0');
});
expect(database.version).toBeDefined();
expect(typeof database.version).toBe('string');
expect(database.version).toEqual('16.0');

it('should return the current opened connections as number', () => {
expect(database.opened_connections).toBeDefined();
expect(typeof database.opened_connections).toBe('number');
expect(database.opened_connections).toEqual(1);
});
expect(database.opened_connections).toBeDefined();
expect(typeof database.opened_connections).toBe('number');
expect(database.opened_connections).toEqual(1);

it('should return the max connections for database', () => {
expect(database.max_connections).toBeDefined();
expect(typeof database.max_connections).toBe('number');
expect(database.max_connections).toBeDefined();
expect(typeof database.max_connections).toBe('number');
});
});
});
1 change: 0 additions & 1 deletion tsconfig.tsbuildinfo

This file was deleted.

Loading