test(wip): apps.resolver

This commit is contained in:
Nicolas Meienberger 2022-07-27 22:15:41 +02:00
parent 86d51a6293
commit c5b4a95abb
10 changed files with 990 additions and 21 deletions

4
.husky/commit-msg Executable file
View file

@ -0,0 +1,4 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no -- commitlint --edit $1

3
commitlint.config.js Normal file
View file

@ -0,0 +1,3 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
};

View file

@ -5,6 +5,7 @@
"scripts": {
"test": "jest",
"prepare": "husky install",
"commit": "git-cz",
"act:test-install": "act --container-architecture linux/amd64 -j test-install",
"act:docker": "act --container-architecture linux/amd64 --secret-file github.secrets -j build-images",
"start:dev": "docker-compose -f docker-compose.dev.yml --env-file .env.dev up --build",
@ -22,7 +23,11 @@
"jest": "^28.1.0",
"js-yaml": "^4.1.0",
"ts-jest": "^28.0.2",
"typescript": "4.6.4"
"typescript": "4.6.4",
"@commitlint/cli": "^17.0.3",
"@commitlint/config-conventional": "^17.0.3",
"@commitlint/cz-commitlint": "^17.0.3",
"commitizen": "^4.2.4"
},
"repository": {
"type": "git",
@ -34,5 +39,10 @@
"url": "https://github.com/meienberger/runtipi/issues"
},
"homepage": "https://github.com/meienberger/runtipi#readme",
"dependencies": {}
"dependencies": {},
"config": {
"commitizen": {
"path": "@commitlint/cz-commitlint"
}
}
}

View file

@ -8,4 +8,7 @@ module.exports = {
collectCoverage: true,
collectCoverageFrom: ['src/**/*.{ts,tsx}'],
passWithNoTests: true,
transform: {
'^.+\\.graphql$': 'graphql-import-node/jest',
},
};

View file

@ -79,6 +79,7 @@
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.0.0",
"graphql-import-node": "^0.0.5",
"jest": "^28.1.0",
"nodemon": "^2.0.15",
"prettier": "2.6.2",

View file

@ -0,0 +1,54 @@
import { DataSource } from 'typeorm';
import { setupConnection, teardownConnection } from '../../../test/connection';
import fs from 'fs';
import { gcall } from '../../../test/gcall';
import App from '../app.entity';
import { listAppInfosQuery } from '../../../test/queries';
import { createApp } from './apps.factory';
import { AppInfo, ListAppsResonse } from '../apps.types';
jest.mock('fs');
let db: DataSource | null = null;
const TEST_SUITE = 'appsresolver';
beforeAll(async () => {
db = await setupConnection(TEST_SUITE);
});
afterAll(async () => {
await db?.destroy();
await teardownConnection(TEST_SUITE);
});
beforeEach(async () => {
jest.resetModules();
jest.resetAllMocks();
jest.restoreAllMocks();
await App.clear();
});
describe('ListAppsInfos', () => {
let app1: AppInfo;
beforeEach(async () => {
const { MockFiles, appInfo } = await createApp();
app1 = appInfo;
// @ts-ignore
fs.__createMockFiles(MockFiles);
});
it('Can list apps', async () => {
const { data } = await gcall<{ listAppsInfo: ListAppsResonse }>({ source: listAppInfosQuery });
expect(data?.listAppsInfo.apps.length).toBe(1);
expect(data?.listAppsInfo.total).toBe(1);
const app = data?.listAppsInfo.apps[0];
expect(app?.id).toBe(app1.id);
expect(app?.author).toBe(app1.author);
expect(app?.name).toBe(app1.name);
expect(app?.available).toBe(app1.available);
});
});

View file

@ -0,0 +1,26 @@
import { ExecutionResult, graphql, GraphQLSchema } from 'graphql';
import { Maybe } from 'type-graphql';
import { createSchema } from '../schema';
interface Options {
source: string;
variableValues?: Maybe<{
[key: string]: any;
}>;
userId?: number;
}
let schema: GraphQLSchema | null = null;
export const gcall = async <T>({ source, variableValues, userId }: Options): Promise<ExecutionResult<T, { [key: string]: any }>> => {
if (!schema) {
schema = await createSchema();
}
return graphql({
schema,
source,
variableValues,
contextValue: { req: { session: { userId } } },
}) as any;
};

View file

@ -0,0 +1,7 @@
/* eslint-disable import/no-extraneous-dependencies */
import 'graphql-import-node';
import { print } from 'graphql/language/printer';
import * as listAppInfos from './listAppInfos.graphql';
export const listAppInfosQuery = print(listAppInfos);

View file

@ -0,0 +1,24 @@
query {
listAppsInfo {
apps {
id
available
port
name
description
version
author
source
categories
url_suffix
form_fields {
max
min
required
env_variable
}
requirements
}
total
}
}

File diff suppressed because it is too large Load diff