Skip to content

Commit

Permalink
wip: e2e tests
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKellerer committed Jun 5, 2024
1 parent 9977a35 commit 2d79f31
Show file tree
Hide file tree
Showing 15 changed files with 88 additions and 158 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/lapis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ jobs:
arguments: generateOpenApiDocs -PopennessLevel=protected
build-root-directory: lapis

- name: Build OpenAPI Spec Multi segmented
uses: gradle/actions/setup-gradle@v3
with:
arguments: generateOpenApiDocs -Psegmented=true
build-root-directory: lapis

- name: Cache .npm
uses: actions/cache@v4
with:
Expand All @@ -109,6 +115,10 @@ jobs:
run: npm run generateLapisClientProtected
working-directory: lapis-e2e

- name: Generate Lapis Client Multi Segmented
run: npm run generateLapisClientMultiSegmented
working-directory: lapis-e2e

- name: Check Format
run: npm run check-format
working-directory: lapis-e2e
Expand Down Expand Up @@ -152,6 +162,7 @@ jobs:
docker compose logs silo > e2e-logs/silo.log
docker compose logs lapisOpen > e2e-logs/lapisOpen.log
docker compose logs lapisProtected > e2e-logs/lapisProtected.log
docker compose logs lapisMultiSegmented > e2e-logs/lapisMultiSegmented.log
env:
SILO_TAG: latest
LAPIS_TAG: ${{ steps.lapisBranchTag.outputs.lapisTag }}
Expand Down
4 changes: 2 additions & 2 deletions lapis-docs/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Create a .env file with this input might NOT work. You might need to properly set CONFIG_FILE as an
# environment variable.
CONFIG_FILE=../lapis-e2e/testData/testDatabaseConfig.yaml
REFERENCE_GENOMES_FILE=../lapis-e2e/testData/reference_genomes.json
CONFIG_FILE=../lapis-e2e/testData/singleSegmented/testDatabaseConfig.yaml
REFERENCE_GENOMES_FILE=../lapis-e2e/testData/singleSegmented/reference_genomes.json
2 changes: 1 addition & 1 deletion lapis-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"astro": "astro",
"check-format": "prettier --check \"**/*.{ts,tsx,json,astro,md,mdx,mjs,cjs}\"",
"format": "prettier --write \"**/*.{ts,tsx,json,astro,md,mdx,mjs,cjs}\"",
"check-types": "CONFIG_FILE=../lapis-e2e/testData/testDatabaseConfig.yaml astro sync && tsc --noEmit",
"check-types": "CONFIG_FILE=../lapis-e2e/testData/singleSegmented/testDatabaseConfig.yaml astro sync && tsc --noEmit",
"e2e": "playwright test"
},
"dependencies": {
Expand Down
9 changes: 2 additions & 7 deletions lapis-e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
"description": "End to end tests for LAPIS backed by SILO",
"scripts": {
"test": "mocha --exit",

"generateLapisClient": "npm run runOpenApiGenerator && npm run copyGeneratedFiles && npm run cleanUpGeneratedFiles",
"runOpenApiGenerator": "openapi-generator-cli generate -i ../lapis/lapis-openapi.json -g typescript-fetch -o generated-sources",
"runOpenApiGenerator": "openapi-generator-cli generate -i ../lapis/lapis-openapi-single-segmented.json -g typescript-fetch -o generated-sources",
"copyGeneratedFiles": "mkdir -p test/lapisClient && cp generated-sources/index.ts generated-sources/runtime.ts test/lapisClient && cp -r generated-sources/apis generated-sources/models test/lapisClient",

"generateLapisClientProtected": "npm run runOpenApiGeneratorProtected && npm run copyGeneratedFilesProtected && npm run cleanUpGeneratedFilesProtected",
"runOpenApiGeneratorProtected": "openapi-generator-cli generate -i ../lapis/lapis-openapi-protected.json -g typescript-fetch -o generated-sources-protected",
"runOpenApiGeneratorProtected": "openapi-generator-cli generate -i ../lapis/lapis-openapi-single-segmented-protected.json -g typescript-fetch -o generated-sources-protected",
"copyGeneratedFilesProtected": "mkdir -p test/lapisClientProtected && cp generated-sources-protected/index.ts generated-sources-protected/runtime.ts test/lapisClientProtected && cp -r generated-sources-protected/apis generated-sources-protected/models test/lapisClientProtected",

"generateLapisClientMultiSegmented": "npm run runOpenApiGeneratorMultiSegmented && npm run copyGeneratedFilesMultiSegmented && npm run cleanUpGeneratedFilesProtected",
"runOpenApiGeneratorMultiSegmented": "openapi-generator-cli generate -i ../lapis/lapis-openapi-multi-segmented.json -g typescript-fetch -o generated-sources-multi-segmented",
"copyGeneratedFilesMultiSegmented": "mkdir -p test/lapisClientMultiSegmented && cp generated-sources-multi-segmented/index.ts generated-sources-multi-segmented/runtime.ts test/lapisClientMultiSegmented && cp -r generated-sources-multi-segmented/apis generated-sources-multi-segmented/models test/lapisClientMultiSegmented",

"cleanUpGeneratedFiles": "rm -rf generated-sources",
"cleanUpGeneratedFilesProtected": "rm -rf generated-sources-protected",
"cleanUpGeneratedFilesMultiSegmented": "rm -rf generated-sources-multi-segmented",

"check-format": "prettier --check .",
"format": "prettier --write ."
},
Expand Down
13 changes: 12 additions & 1 deletion lapis-e2e/test/aggregated.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { basePath, lapisClient } from './common';
import { basePath, lapisClient, lapisClientMultiSegmented } from './common';
import fs from 'fs';
import { AggregatedPostRequest, AggregatedResponse } from './lapisClient';

Expand Down Expand Up @@ -46,6 +46,17 @@ describe('The /aggregated endpoint', () => {
})
);

it('should correcty handle aggregated request with multiple segments', async () => {
const result = await lapisClientMultiSegmented.postAggregated1({
aggregatedPostRequest: {
nucleotideMutations: 'L:T1A,M:T1C',
},
});

expect(result.data).to.have.length(1);
expect(result.data[0]).to.have.property('count', 1);
});

it('should correctly handle multiple mutation requests in GET requests', async () => {
const urlParams = new URLSearchParams({
nucleotideMutations: 'T1-,A23062T',
Expand Down
15 changes: 15 additions & 0 deletions lapis-e2e/test/alignedNucleotideSequence.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { expect } from 'chai';
import {
basePath,
expectIsZstdEncoded,
lapisMultiSegmentedSequenceController,
lapisSingleSegmentedSequenceController,
sequenceData,
} from './common';
Expand All @@ -20,6 +21,20 @@ describe('The /alignedNucleotideSequence endpoint', () => {
expect(sequences[0]).to.have.length(29903);
});

it('should return aligned nucleotide sequences for multi segmented sequences', async () => {
const result = await lapisMultiSegmentedSequenceController.postAlignedNucleotideSequence({
nucleotideSequenceRequest: { country: 'Switzerland' },
segment: 'M',
});

const { primaryKeys, sequences } = sequenceData(result);

expect(primaryKeys).to.have.length(6);
expect(sequences).to.have.length(6);
expect(primaryKeys[0]).to.equal('>key_0');
expect(sequences[0]).to.equal('CGGG');
});

it('should order ascending by specified fields', async () => {
const result = await lapisSingleSegmentedSequenceController.postAlignedNucleotideSequence({
nucleotideSequenceRequest: { orderBy: [{ field: 'primaryKey', type: 'ascending' }] },
Expand Down
2 changes: 1 addition & 1 deletion lapis-e2e/test/aminoAcidSequence.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import { basePath, lapisClient, sequenceData } from './common';
import { lapisClient, sequenceData } from './common';

describe('The /alignedAminoAcidSequence endpoint', () => {
it('should return amino acid sequences for Switzerland', async () => {
Expand Down
9 changes: 4 additions & 5 deletions lapis-e2e/test/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
LapisControllerApi as LapisControllerApiProtected,
Configuration as ConfigurationProtected,
} from './lapisClientProtected';
import {MultiSegmentedSequenceControllerApi} from "./lapisClientMultiSegmented";
import { MultiSegmentedSequenceControllerApi } from './lapisClientMultiSegmented';

export const basePath = 'http://localhost:8090';
export const basePathProtected = 'http://localhost:8092';
Expand Down Expand Up @@ -44,16 +44,15 @@ export const lapisClientProtected = new LapisControllerApiProtected(
new ConfigurationProtected({ basePath: basePathProtected })
).withMiddleware(middleware);
export const lapisClientMultiSegmented = new LapisControllerApiMultiSegmented(
new Configuration({ basePath: basePathMultiSegmented })
).withMiddleware(middleware);

new Configuration({ basePath: basePathMultiSegmented })
).withMiddleware(middleware);

export const lapisSingleSegmentedSequenceController = new SingleSegmentedSequenceControllerApi(
new Configuration({ basePath })
).withMiddleware(middleware);

export const lapisMultiSegmentedSequenceController = new MultiSegmentedSequenceControllerApi(
new Configuration({ basePath: basePathMultiSegmented })
new Configuration({ basePath: basePathMultiSegmented })
).withMiddleware(middleware);

export function sequenceData(serverResponse: string) {
Expand Down
24 changes: 9 additions & 15 deletions lapis-e2e/test/nucleotideInsertions.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import {basePath, lapisClient, lapisClientMultiSegmented} from './common';
import { basePath, lapisClient, lapisClientMultiSegmented } from './common';

describe('The /nucleotideInsertions endpoint', () => {
let someInsertion = 'ins_25701:CCC';
Expand All @@ -19,24 +19,18 @@ describe('The /nucleotideInsertions endpoint', () => {
});

it('should return nucleotide insertions for multi segmented sequences', async () => {
const result = await lapisClientMultiSegmented.postNucleotideInsertions1(
{
insertionsRequest: { country: 'Switzerland' },
}
);
const result = await lapisClientMultiSegmented.postNucleotideInsertions1({
insertionsRequest: { country: 'Switzerland' },
});

expect(result.data).to.have.length(2);
expect(result.data).to.have.length(3);

const insertionsFirstSegment = result.data.find(
mutationData => mutationData.insertion === 'ins_L:123:AB'
);
expect(insertionsFirstSegment?.count).to.equal(1);
const insertionsFirstSegment = result.data.find(mutationData => mutationData.insertion === 'ins_L:1:AB');
expect(insertionsFirstSegment?.count).to.equal(2);

const insertionsSecondSegment = result.data.find(
mutationData => mutationData.insertion === 'ins_M:234:BC'
);
const insertionsSecondSegment = result.data.find(mutationData => mutationData.insertion === 'ins_M:2:BC');
expect(insertionsSecondSegment?.count).to.equal(1);
})
});

it('should order by specified fields', async () => {
const ascendingOrderedResult = await lapisClient.postNucleotideInsertions1({
Expand Down
11 changes: 5 additions & 6 deletions lapis-e2e/test/nucleotideMutations.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect } from 'chai';
import {basePath, lapisClient, lapisClientMultiSegmented} from './common';
import { basePath, lapisClient, lapisClientMultiSegmented } from './common';

describe('The /nucleotideMutations endpoint', () => {
let mutationWithLessThan10PercentProportion = 'C19220T';
Expand Down Expand Up @@ -31,22 +31,21 @@ describe('The /nucleotideMutations endpoint', () => {

it('should return mutations proportions for multi segmented', async () => {
const result = await lapisClientMultiSegmented.postNucleotideMutations1({
sequenceFiltersWithMinProportion: { country: 'Switzerland', minProportion: 0.0 },
});
})
sequenceFiltersWithMinProportion: { country: 'Switzerland', minProportion: 0.0 },
});

expect(result.data).to.have.length(2);

const mutationProportionOnFirstSegment = result.data.find(
mutationData => mutationData.mutation === 'L:T1A'
);
expect(mutationProportionOnFirstSegment?.count).to.equal(1);
expect(mutationProportionOnFirstSegment?.count).to.equal(2);

const mutationProportionOnSecondSegment = result.data.find(
mutationData => mutationData.mutation === 'M:T1A'
);
expect(mutationProportionOnSecondSegment?.count).to.equal(1);
})
});

it('should return mutation proportions for Switzerland with minProportion 0.5', async () => {
const result = await lapisClient.postNucleotideMutations1({
Expand Down
106 changes: 6 additions & 100 deletions lapis-e2e/testData/multiSegmented/input_file.ndjson

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lapis-e2e/testData/multiSegmented/preprocessingConfig.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
ndjsonInputFilename: "input_file.ndjson"
referenceGenomeFilename: reference_genomes.json
ndjsonInputFilename: 'input_file.ndjson'
referenceGenomeFilename: reference_genomes.json
Loading

0 comments on commit 2d79f31

Please sign in to comment.