-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import ContextProvider from './testContext'; | ||
|
||
beforeAll(async () => { | ||
await ContextProvider.Instance.setUpContext(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
}); | ||
}); |