Skip to content

Commit

Permalink
Update e2e unit test
Browse files Browse the repository at this point in the history
* Updated how to upload the dictionaries.
  • Loading branch information
goetzrrGit committed Sep 13, 2024
1 parent 9e6cfd8 commit ad4a62f
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 52 deletions.
2 changes: 1 addition & 1 deletion sequencing-server/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default {
testRunner: 'jest-circus/runner',
// testRegex: "(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
testRegex: '((\\.|/)(test|spec))\\.(jsx?|tsx?)$',
testPathIgnorePatterns: ['/node_modules/', '/build/'],
testPathIgnorePatterns: ['/node_modules/', '/build/', '/plugins/'],
coverageReporters: ['html'],
setupFiles: ['dotenv/config', './src/polyfills.ts'],
globalSetup: './jestGlobalSetup.js',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ let parcelId: number;

beforeAll(async () => {
graphqlClient = await getGraphQLClient();
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
parcelId = (
await insertParcel(
graphqlClient,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ let parcelId: number;

beforeAll(async () => {
graphqlClient = await getGraphQLClient();
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
paramaterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
paramaterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
parcelId = (
await insertParcel(
graphqlClient,
Expand Down
6 changes: 3 additions & 3 deletions sequencing-server/test/command-expansion.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ let parcelId: number;

beforeAll(async () => {
graphqlClient = await getGraphQLClient();
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
parcelId = (
await insertParcel(
graphqlClient,
Expand Down
6 changes: 3 additions & 3 deletions sequencing-server/test/command-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ let parameterDictionaryId: number;

beforeAll(async () => {
graphqlClient = await getGraphQLClient();
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
});

afterAll(async () => {
Expand Down
6 changes: 3 additions & 3 deletions sequencing-server/test/db-state.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ beforeAll(async () => {
});

beforeEach(async () => {
commandDictonaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictonaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
parcelId = (
await insertParcel(graphqlClient, commandDictonaryId, channelDictionaryId, parameterDictionaryId, 'db-parcel-test')
).parcelId;
Expand Down
30 changes: 15 additions & 15 deletions sequencing-server/test/dictionary.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,43 @@ beforeAll(async () => {
describe('upload dictionaries', () => {
it('should upload a command dictionary and all of the fields should be populated correctly', async () => {
// During the test we use a uuid for the mission so there's no conflicting command dictionaries.
const { id, dictionary_path, mission, parsed_json } = await insertDictionary(graphqlClient, DictionaryType.COMMAND);
const { command } = await insertDictionary(graphqlClient, DictionaryType.COMMAND);

expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/command_lib.${mission}.ts`);
expect(command.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${command.mission}/command_lib.${command.mission}.ts`);

expect(parsed_json).toStrictEqual(
ampcs.parse(commandDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, mission)),
expect(command.parsed_json).toStrictEqual(
ampcs.parse(commandDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, command.mission)),
);

await removeDictionary(graphqlClient, id, DictionaryType.COMMAND);
await removeDictionary(graphqlClient, command.id, DictionaryType.COMMAND);
}, 30000);

it('should upload a channel dictionary and all of the fields should be populated correctly', async () => {
// During the test we use a uuid for the mission so there's no conflicting command dictionaries.
const { id, dictionary_path, mission, parsed_json } = await insertDictionary(graphqlClient, DictionaryType.CHANNEL);
const { channel } = await insertDictionary(graphqlClient, DictionaryType.CHANNEL);

expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/channel_lib.${mission}.ts`);
expect(channel.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${channel.mission}/channel_lib.${channel.mission}.ts`);

expect(parsed_json).toEqual(
ampcs.parseChannelDictionary(channelDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, mission)),
expect(channel.parsed_json).toEqual(
ampcs.parseChannelDictionary(channelDictionaryString.replace(/(Banana Nation|1.0.0.0)/g, channel.mission)),
);

await removeDictionary(graphqlClient, id, DictionaryType.CHANNEL);
await removeDictionary(graphqlClient, channel.id, DictionaryType.CHANNEL);
}, 30000);

it('should upload a parameter dictionary and all of the fields should be populated correctly', async () => {
// During the test we use a uuid for the mission so there's no conflicting command dictionaries.
const { id, dictionary_path, mission, parsed_json } = await insertDictionary(
const { parameter } = await insertDictionary(
graphqlClient,
DictionaryType.PARAMETER,
);

expect(dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${mission}/parameter_lib.${mission}.ts`);
expect(parameter.dictionary_path).toBe(`/usr/src/app/sequencing_file_store/${parameter.mission}/parameter_lib.${parameter.mission}.ts`);

expect(parsed_json).toEqual(
ampcs.parseParameterDictionary(parameterDictionaryString.replace(/(Banana Nation|1.0.0.1)/g, mission)),
expect(parameter.parsed_json).toEqual(
ampcs.parseParameterDictionary(parameterDictionaryString.replace(/(Banana Nation|1.0.0.1)/g, parameter.mission)),
);

await removeDictionary(graphqlClient, id, DictionaryType.PARAMETER);
await removeDictionary(graphqlClient, parameter.id, DictionaryType.PARAMETER);
}, 30000);
});
6 changes: 3 additions & 3 deletions sequencing-server/test/sequence-generation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ let parcelId: number;

beforeAll(async () => {
graphqlClient = await getGraphQLClient();
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).id;
commandDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.COMMAND)).command.id;
channelDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.CHANNEL)).channel.id;
parameterDictionaryId = (await insertDictionary(graphqlClient, DictionaryType.PARAMETER)).parameter.id;
parcelId = (
await insertParcel(
graphqlClient,
Expand Down
53 changes: 35 additions & 18 deletions sequencing-server/test/testUtils/Dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ export async function insertDictionary(
graphqlClient: GraphQLClient,
type: DictionaryType,
): Promise<{
id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: CommandDictionary | ChannelDictionary | ParameterDictionary;
command: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: CommandDictionary}
parameter: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: ParameterDictionary}
channel: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: ChannelDictionary}
}> {
let dictonaryString = commandDictionaryString;
switch (type) {
Expand All @@ -39,28 +49,35 @@ export async function insertDictionary(
}
const res = await graphqlClient.request<{
uploadDictionary: {
id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: CommandDictionary | ChannelDictionary | ParameterDictionary;
command: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: CommandDictionary}
parameter: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: ParameterDictionary}
channel: {id: number;
dictionary_path: string;
mission: string;
version: string;
parsed_json: ChannelDictionary}
};
}>(
gql`
mutation PutDictionary($dictionary: String!, $type: String!) {
uploadDictionary(dictionary: $dictionary, type: $type) {
id
dictionary_path
mission
version
parsed_json
mutation PutDictionary($dictionary: String!) {
uploadDictionary(dictionary: $dictionary) {
command
parameter
channel
}
}
`,
{
// Generate a UUID for the command dictionary name and version to avoid conflicts when testing.
dictionary: dictonaryString.replace(/(Banana Nation|1.0.0.0|1.0.0.1)/g, randomUUID()),
type,
},
);

Expand Down

0 comments on commit ad4a62f

Please sign in to comment.