Skip to content

Commit

Permalink
Add utils2
Browse files Browse the repository at this point in the history
  • Loading branch information
manelcecs committed Nov 10, 2023
1 parent f23b36c commit 1c0d811
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 32 deletions.
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config: Config.InitialOptions = {
transformIgnorePatterns: ['node_modules/(?!(@unocha)/)'],
modulePathIgnorePatterns: ['<rootDir>/test/'],
setupFilesAfterEnv: ['<rootDir>/tests/test-environment-setup.ts'],
testTimeout: 100000,
testTimeout: 100_000,
};

export default config;
22 changes: 11 additions & 11 deletions tests/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
version: '3.8'
services:
db:
image: postgres:14-alpine3.18
container_name: hpc_postgres_test_api
ports:
- 6432:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=test
- POSTGRES_DB=test
volumes:
- ./migration/migration.sql:/docker-entrypoint-initdb.d/init.sql
image: postgres:14-alpine3.18
container_name: hpc_postgres_test_api
ports:
- 6432:5432
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=test
- POSTGRES_DB=test
volumes:
- ./migration/migration.sql:/docker-entrypoint-initdb.d/init.sql
solr:
image: solr:8.11.2-slim
environment:
Expand Down Expand Up @@ -38,4 +38,4 @@ services:
environment:
PORT: 80
hostname: hidapi
container_name: test_hidservice_test_api
container_name: test_hidservice_test_api
13 changes: 6 additions & 7 deletions tests/testContext.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ApolloServer } from 'apollo-server-hapi';
import Knex from 'knex';
import v4Models, { Database } from '@unocha/hpc-api-core/src/db';
import createApolloTestServer from './utils/server';
import v4Models, { type Database } from '@unocha/hpc-api-core/src/db';
import { type ApolloServer } from 'apollo-server-hapi';
import type Knex from 'knex';
import { createDbConnetion } from './utils/connection';
import createApolloTestServer from './utils/server';

interface IContext {
models?: Database;
Expand All @@ -29,10 +29,9 @@ export default class ContextProvider implements IContext {
public static get Instance(): ContextProvider {
if (this._instance) {
return this._instance;
} else {
this._instance = new ContextProvider();
return this._instance;
}
this._instance = new ContextProvider();
return this._instance;
}

public async setUpContext(): Promise<void> {
Expand Down
4 changes: 2 additions & 2 deletions tests/utils/connection.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as t from 'io-ts';
import Knex from 'knex';
// TODO: apply singleton pattern to avoid creating the same connection for each test

const CONFIG = t.type({
db: t.type({
poolMin: t.number,
Expand Down Expand Up @@ -36,7 +36,7 @@ export async function createDbConnetion(config: t.TypeOf<typeof CONFIG>) {
await knex.raw('SELECT now()');

return knex;
} catch (error) {
} catch {
throw new Error(
'Unable to connect to Postgres via Knex. Ensure a valid connection.'
);
Expand Down
19 changes: 11 additions & 8 deletions tests/utils/server.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as Hapi from '@hapi/hapi';
import { type Database } from '@unocha/hpc-api-core/src/db';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import {
ApolloServer,
ApolloServerPluginStopHapiServer,
} from 'apollo-server-hapi';
import { CONFIG } from '../../config';
import { buildSchema } from 'type-graphql';
import type Knex from 'knex';
import PlatformPath from 'node:path';
import 'reflect-metadata';
import * as Hapi from '@hapi/hapi';
import { ApolloServerPluginLandingPageGraphQLPlayground } from 'apollo-server-core';
import { join } from 'path';
import { buildSchema } from 'type-graphql';
import { Container } from 'typedi';
import { Database } from '@unocha/hpc-api-core/src/db';
import { CONFIG } from '../../config';
import { getTokenFromRequest } from '../../src/common-libs/auth';
import Knex from 'knex';

export default async function createApolloTestServer(
connection: Knex,
Expand All @@ -20,7 +20,10 @@ export default async function createApolloTestServer(
) {
const schema = await buildSchema({
resolvers: [
join(__dirname, '../../src/domain-services/**/resolver.{ts,js}'),
PlatformPath.join(
__dirname,
'../../src/domain-services/**/resolver.{ts,js}'
),
],
container: Container, // Register the 3rd party IOC container
});
Expand Down
6 changes: 3 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2519,9 +2519,9 @@ eastasianwidth@^0.2.0:
integrity sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==

electron-to-chromium@^1.4.535:
version "1.4.579"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.579.tgz#40ddec29bb5549908e82ccd652cf5da2e5900c23"
integrity sha512-bJKvA+awBIzYR0xRced7PrQuRIwGQPpo6ZLP62GAShahU9fWpsNN2IP6BSP1BLDDSbxvBVRGAMWlvVVq3npmLA==
version "1.4.580"
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.4.580.tgz#2f8f70f70733a6be1fb6f31de1224e6dc4bb196d"
integrity sha512-T5q3pjQon853xxxHUq3ZP68ZpvJHuSMY2+BZaW3QzjS4HvNuvsMmZ/+lU+nCrftre1jFZ+OSlExynXWBihnXzw==

emitter-listener@^1.1.1:
version "1.1.2"
Expand Down

0 comments on commit 1c0d811

Please sign in to comment.