test(apps.resolver): wip testing resolvers

This commit is contained in:
Nicolas Meienberger 2022-07-28 19:50:43 +02:00
parent 05c8dff8e2
commit c37a0eb6d5
3 changed files with 74 additions and 2 deletions

View file

@ -3,12 +3,16 @@ 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 { getAppQuery, listAppInfosQuery } from '../../../test/queries';
import { createApp } from './apps.factory';
import { AppInfo, ListAppsResonse } from '../apps.types';
import { AppInfo, AppStatusEnum, ListAppsResonse } from '../apps.types';
jest.mock('fs');
type TApp = App & {
info: AppInfo;
};
let db: DataSource | null = null;
const TEST_SUITE = 'appsresolver';
@ -52,3 +56,44 @@ describe('ListAppsInfos', () => {
expect(app?.available).toBe(app1.available);
});
});
describe('GetApp', () => {
let app1: AppInfo;
let app2: AppInfo;
beforeEach(async () => {
const app1create = await createApp();
const app2create = await createApp(true);
app1 = app1create.appInfo;
app2 = app2create.appInfo;
// @ts-ignore
fs.__createMockFiles(Object.assign(app1create.MockFiles, app2create.MockFiles));
});
it('Can get app', async () => {
const { data } = await gcall<{ getApp: TApp }>({
source: getAppQuery,
variableValues: { id: app1.id },
});
expect(data?.getApp.info.id).toBe(app1.id);
expect(data?.getApp.status).toBe(AppStatusEnum.MISSING.toUpperCase());
const { data: data2 } = await gcall<{ getApp: TApp }>({
source: getAppQuery,
variableValues: { id: app2.id },
});
expect(data2?.getApp.info.id).toBe(app2.id);
});
it("Should return an error if app doesn't exist", async () => {
const { data, errors } = await gcall<{ getApp: TApp }>({
source: getAppQuery,
variableValues: { id: 'not-existing' },
});
expect(errors?.[0].message).toBe('App not-existing not found');
expect(data?.getApp).toBeUndefined();
});
});

View file

@ -0,0 +1,25 @@
query GetApp($id: String!) {
getApp(id: $id) {
status
config
info {
id
available
port
name
description
version
author
source
categories
url_suffix
form_fields {
max
min
required
env_variable
}
requirements
}
}
}

View file

@ -3,5 +3,7 @@ import 'graphql-import-node';
import { print } from 'graphql/language/printer';
import * as listAppInfos from './listAppInfos.graphql';
import * as getApp from './getApp.graphql';
export const listAppInfosQuery = print(listAppInfos);
export const getAppQuery = print(getApp);