Newer
Older
it("has the database", async () => {
const client = new Client({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
password: process.env.POSTGRES_PASSWORD,
});
await client.connect();
const query = await client.query(
`SELECT * FROM pg_database WHERE datname='${process.env.POSTGRES_DB}'`
);
expect(query.rows.length).toBeGreaterThan(0);
await client.end();
});
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
let client: Client;
const databaseTables = [
{
table_name: "checkin",
columns: [
{ column_name: "id", data_type: "uuid" },
{ column_name: "startTime", data_type: "timestamp with time zone" },
{
column_name: "estimatedEndTime",
data_type: "timestamp with time zone",
},
{ column_name: "boatId", data_type: "uuid" },
{ column_name: "createdAt", data_type: "timestamp with time zone" },
{ column_name: "updatedAt", data_type: "timestamp with time zone" },
{ column_name: "email", data_type: "character varying" },
{
column_name: "fullNameOfResponsableClient",
data_type: "character varying",
},
{ column_name: "additionalClients", data_type: "ARRAY" },
],
},
{
table_name: "boat",
columns: [
{ column_name: "status", data_type: "boolean" },
{ column_name: "createdAt", data_type: "timestamp with time zone" },
{ column_name: "updatedAt", data_type: "timestamp with time zone" },
{ column_name: "boattype", data_type: "uuid" },
{ column_name: "id", data_type: "uuid" },
{ column_name: "name", data_type: "character varying" },
{ column_name: "tags", data_type: "ARRAY" },
],
},
{
table_name: "boattype",
columns: [
{ column_name: "id", data_type: "uuid" },
{ column_name: "seats", data_type: "integer" },
{ column_name: "createdAt", data_type: "timestamp with time zone" },
{ column_name: "updatedAt", data_type: "timestamp with time zone" },
{ column_name: "name", data_type: "character varying" },
],
},
{
table_name: "employee",
columns: [
{ column_name: "id", data_type: "uuid" },
{ column_name: "createdAt", data_type: "timestamp with time zone" },
{ column_name: "updatedAt", data_type: "timestamp with time zone" },
{ column_name: "last_name", data_type: "character varying" },
{ column_name: "password", data_type: "character varying" },
{ column_name: "role", data_type: "character varying" },
{ column_name: "email", data_type: "character varying" },
{ column_name: "first_name", data_type: "character varying" },
],
},
];
beforeAll(async () => {
client = new Client({
user: process.env.POSTGRES_USER,
host: process.env.POSTGRES_HOST,
database: process.env.POSTGRES_DB,
password: process.env.POSTGRES_PASSWORD,
afterAll(async () => await client.end());
it("has the correct tables", async () => {
const query = await client.query(
`SELECT table_name FROM information_schema.tables WHERE table_schema='public'`
);
const tableNames = query.rows.map((row) => row.table_name).sort();
const shouldHaveTableNames = databaseTables
.map((table) => table.table_name)
.sort();
expect(tableNames).toEqual(shouldHaveTableNames);
});
it.each(databaseTables)(
"has correct columns for each table",
async ({ table_name, columns }) => {
const query = await client.query(
`SELECT column_name, data_type FROM information_schema.columns WHERE table_name='${table_name}';`
);
const queryColumns = query.rows;
for (let queryColumn of queryColumns) {
expect(columns).toContainEqual(queryColumn);
}
}