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
+4
View File
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
};
+3800
View File
File diff suppressed because it is too large Load Diff
+9 -8
View File
@@ -4,7 +4,9 @@
"description": "",
"main": "src/index.js",
"scripts": {
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts"
"start": "nodemon -w src --ext ts --exec ts-node src/index.ts",
"test": "jest --detectOpenHandles",
"test:dev": "jest --watch"
},
"author": "",
"license": "ISC",
@@ -12,6 +14,7 @@
"apollo-datasource": "^0.8.0",
"apollo-datasource-rest": "^0.11.0",
"apollo-server": "^2.22.2",
"async-redis": "^1.1.7",
"datasource-sql": "^1.4.0",
"dotenv": "^8.2.0",
"graphql": "^15.5.0",
@@ -27,16 +30,14 @@
"validator": "^13.5.2"
},
"devDependencies": {
"@types/jest": "^26.0.22",
"@typescript-eslint/eslint-plugin": "^4.21.0",
"@typescript-eslint/parser": "^4.21.0",
"eslint": "^7.23.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-prettier": "^3.3.1"
},
"jest": {
"testPathIgnorePatterns": [
"/node_modules/",
"/__utils"
]
"eslint-plugin-prettier": "^3.3.1",
"jest": "^26.6.3",
"testcontainers": "^7.7.0",
"ts-jest": "^26.5.5"
}
}
+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
);