Add embryo to e2e tests

This commit is contained in:
Niklas Fondberg
2021-04-19 12:54:38 +02:00
parent 6bd48467a3
commit bf01ecba9c
5 changed files with 3903 additions and 8 deletions
+71
View File
@@ -0,0 +1,71 @@
import fs from 'fs';
import { resolve } from 'path';
import { GenericContainer, StartedTestContainer } from 'testcontainers';
import Knex from 'knex';
import knexTinyLogger from 'knex-tiny-logger';
jest.setTimeout(18000_000);
const createKnexDb = (mappedPort: string, database: string) => {
const db = Knex({
client: 'pg',
connection: `postgresql://testuser:test@localhost:${mappedPort}/${database}`,
pool: { min: 0 },
});
knexTinyLogger(db);
return db;
};
const createDB = async (mappedPort): Promise<Knex> => {
const initialDb = createKnexDb(mappedPort, 'postgres');
await initialDb.raw('CREATE DATABASE photowalltest');
await initialDb.destroy();
const db = createKnexDb(mappedPort, 'photowalltest');
const sql = fs.readFileSync(resolve(__dirname, 'seed.sql')).toString();
await db.raw(sql);
return db;
};
const openTestContainer = async (): Promise<StartedTestContainer> => {
const container = await new GenericContainer('postgres')
.withEnv('POSTGRES_USER', 'testuser')
.withEnv('POSTGRES_PASSWORD', 'test')
.withEnv('POSTGRES_DB', 'apidb')
.withExposedPorts(5432)
.start();
// const stream = await container.logs();
// stream
// .on('data', (line) => console.debug(line))
// .on('err', (line) => console.error(line))
// .on('end', () => console.debug('Docker Container Stream closed...'));
return container;
};
function sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
describe('GenericContainer', () => {
let container: StartedTestContainer;
let db: Knex;
beforeAll(async () => {
container = await openTestContainer();
db = await createDB(container.getMappedPort(5432));
});
afterAll(async () => {
await container.stop();
await db.destroy();
});
it('works', async () => {
const res = await db.raw('select now()');
expect(res.rows[0]['now']).toBeInstanceOf(Date);
await sleep(2000000);
});
});
+19
View File
@@ -0,0 +1,19 @@
CREATE EXTENSION IF NOT EXISTS unaccent WITH SCHEMA public;
CREATE TABLE locales (
id integer NOT NULL,
value character(5),
esales_locale character varying NOT NULL,
fallback_id integer,
name text NOT NULL
);
CREATE TABLE markets (
id integer NOT NULL,
name character varying,
locale_id integer
);
CREATE TABLE market_locales (
id integer NOT NULL,
market_id integer NOT NULL,
locale_id integer NOT NULL,
name text NOT NULL
);