diff --git a/tests/resolvers/software-info.spec.ts b/tests/resolvers/software-info.spec.ts new file mode 100644 index 00000000..004c7586 --- /dev/null +++ b/tests/resolvers/software-info.spec.ts @@ -0,0 +1,49 @@ +import { version as softwareVersion } from '../../package.json'; +import ContextProvider from '../testContext'; + +const testSoftwareInfo = + (version: boolean, title: boolean, status: boolean) => async () => { + const response = + await ContextProvider.Instance.apolloTestServer.executeOperation({ + query: `query { softwareInfo { ${title ? 'title' : ''} ${ + status ? 'status' : '' + } ${version ? 'version' : ''} } }`, + }); + + expect(response).toBeDefined(); + expect(response.errors).toBeUndefined(); + expect(response.data).toBeDefined(); + + const data = response.data; + expect(data?.softwareInfo).toBeDefined(); + expect(data?.softwareInfo.length).toBeGreaterThan(0); + const softwareInfo = data?.softwareInfo[0]; + + if (version) { + expect(softwareInfo.version).toBe(softwareVersion); + } else { + expect(softwareInfo.version).toBeUndefined(); + } + + if (title) { + expect(softwareInfo.title).toBeDefined(); + } else { + expect(softwareInfo.title).toBeUndefined(); + } + + if (status) { + expect(softwareInfo.status).toBeDefined(); + } else { + expect(softwareInfo.status).toBeUndefined(); + } + }; + +describe('Query should return Software info', () => { + it('All data should be returned', testSoftwareInfo(true, true, true)); + + it('Only version should be returned', testSoftwareInfo(true, false, false)); + + it('Only title should be returned', testSoftwareInfo(false, true, false)); + + it('Only status should be returned', testSoftwareInfo(false, false, true)); +}); diff --git a/tests/test-environment-setup.ts b/tests/test-environment-setup.ts new file mode 100644 index 00000000..f6d566c5 --- /dev/null +++ b/tests/test-environment-setup.ts @@ -0,0 +1,5 @@ +import ContextProvider from './testContext'; + +beforeAll(async () => { + await ContextProvider.Instance.setUpContext(); +}); diff --git a/tests/test-environment.spec.ts b/tests/test-environment.spec.ts new file mode 100644 index 00000000..e4ee379b --- /dev/null +++ b/tests/test-environment.spec.ts @@ -0,0 +1,30 @@ +import ContextProvider from './testContext'; + +const context = ContextProvider.Instance; + +describe('Ensure test environment is setup correctly', () => { + it('should be able to run a test', () => { + expect(true).toBe(true); + }); +}); + +describe('ContextProvider should be defined', () => { + it('should be defined', () => { + expect(context).toBeDefined(); + }); + + it('should have a connection', () => { + expect(context.conn).toBeDefined(); + }); + + it('connection should be a knex connection', () => { + expect(context.conn).toBeDefined(); + expect(context.conn?.client.config.client).toEqual('pg'); + }); + + it('knex connection should be connected', async () => { + expect(context.conn).toBeDefined(); + const res = await context.conn?.raw('SELECT NOW()'); + expect(res.rows[0].now).toBeDefined(); + }); +});