Skip to content

Commit

Permalink
implement tests for autoacmg client
Browse files Browse the repository at this point in the history
  • Loading branch information
gromdimon committed Sep 20, 2024
1 parent 7e1e294 commit d906879
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions frontend/src/api/autoacmg/client.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { beforeEach, describe, expect, it, vi } from 'vitest'
import createFetchMock from 'vitest-fetch-mock'

import AUTOACMG_SEQVAR_RESULT from './brca1_seqvar.json'
import { AutoACMGClient } from './client'

const fetchMocker = createFetchMock(vi)

describe('AutoACMGClient', () => {
beforeEach(() => {
fetchMocker.enableMocks()
fetchMocker.resetMocks()
})

it('should be created', () => {
const client = new AutoACMGClient()
expect(client).toBeDefined()
})

it('should classify a sequence variant', async () => {
fetchMocker.mockResponseOnce(JSON.stringify(AUTOACMG_SEQVAR_RESULT))

const client = new AutoACMGClient()
const result = await client.classifySequenceVariant({
genomeBuild: 'grch37',
chrom: '17',
pos: 41245466,
del: 'G',
ins: 'A',
userRepr: 'GRCh37-17-41245466-G-A'
})

expect(result).toEqual(AUTOACMG_SEQVAR_RESULT)

Check failure on line 33 in frontend/src/api/autoacmg/client.spec.ts

View workflow job for this annotation

GitHub Actions / Frontend-Test

src/api/autoacmg/client.spec.ts > AutoACMGClient > should classify a sequence variant

AssertionError: expected { seqvar: { …(6) }, …(2) } to deeply equal { prediction: { …(3) } } - Expected + Received Object { - "prediction": Object { "criteria": Object { "ba1": Object { "description": "", "name": "BA1", "prediction": "failed", "strength": "benign_stand_alone", "summary": "An error occurred while predicting PM2, BA1, BS1, BS2 criteria: No allele frequency found in gnomad data.", }, "bp1": Object { "description": "", "name": "BP1", "prediction": "not_applicable", "strength": "pathogenic_strong", "summary": "Variant is not synonymous, missense or inframe indel, or in an important domain, or predicted to affect splicing. BP1 is not met.", }, "bp2": Object { "description": "", "name": "BP2", "prediction": "not_automated", "strength": "benign_supporting", "summary": "", }, "bp3": Object { "description": "", "name": "BP3", "prediction": "not_applicable", "strength": "benign_supporting", "summary": "BP3 is not applicable for the ENIGMA VCEP.", }, "bp4": Object { "description": "", "name": "BP4", "prediction": "not_applicable", "strength": "benign_supporting", "summary": "BP4 criteria not met.", }, "bp5": Object { "description": "", "name": "BP5", "prediction": "not_automated", "strength": "benign_supporting", "summary": "", }, "bp6": Object { "description": "", "name": "BP6", "prediction": "depricated", "strength": "benign_supporting", "summary": "", }, "bp7": Object { "description": "", "name": "BP7", "prediction": "not_applicable", "strength": "benign_supporting", "summary": "Variant is not synonymous or not in an important domain, or intronic variant is conserved. BP7 is not met.", }, "bs1": Object { "description": "", "name": "BS1", "prediction": "failed", "strength": "benign_strong", "summary": "An error occurred while predicting PM2, BA1, BS1, BS2 criteria: No allele frequency found in gnomad data.", }, "bs2": Object { "description": "", "name": "BS2", "prediction": "failed", "strength": "benign_strong", "summary": "An error occurred while predicting PM2, BA1, BS1, BS2 criteria: No allele frequency found in gnomad data.", }, "bs3": Object { "description": "", "name": "BS3", "prediction": "not_automated", "strength": "benign_strong", "summary": "", }, "bs4": Object { "description": "", "name": "BS4", "prediction": "not_automated", "strength": "benign_strong", "summary": "", }, "pm1": Object { "description": "", "name": "PM1", "prediction": "not_applicable", "strength": "pathogenic_moderate", "summary": "PM1 is not applicable for BRCA1 and BRCA2.", }, "pm2": Object { "description": "", "name": "PM2", "prediction": "failed", "strength": "pathogenic_moderate", "summary": "An error occurred while predicting PM2, BA1, BS1, BS2 criteria: No allele frequency found in gnomad data.", }, "pm3": Object { "description": "", "name": "PM3", "prediction": "not_automated", "strength": "pathogenic_moderate", "summary": "", }, "pm4": Object { "description": "", "name": "PM4", "prediction": "not_applicable", "strength": "pathogenic_moderate", "summary": "PM4 is not applicable for the ENIGMA VCEP.", }, "pm5": Object { "description": "", "name": "PM5", "prediction": "not_applicable", "strength": "pathogenic_moderate", "summary": "Variant affects splicing. P
expect(fetchMocker).toHaveBeenCalledTimes(1)
expect(fetchMocker).toHaveBeenCalledWith(
'http://localhost:8080/api/v1/proxy/autoacmg/api/v1/predict/seqvar?variant_name=chr17:41245466:G:A&genome_release=grch37',
expect.objectContaining({
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
)
})

it('should throw an error for non-200 response', async () => {
fetchMocker.mockResponseOnce(JSON.stringify({ error: 'Not found' }), { status: 404 })

const client = new AutoACMGClient()
await expect(
client.classifySequenceVariant({
genomeBuild: 'grch37',
chrom: '17',
pos: 41245466,
del: 'G',
ins: 'A',
userRepr: 'GRCh37-17-41245466-G-A'
})
).rejects.toThrow('HTTP error! status: 404')
})

it('should throw an error for invalid JSON response', async () => {
fetchMocker.mockResponseOnce('Invalid JSON')

const client = new AutoACMGClient()
await expect(
client.classifySequenceVariant({
genomeBuild: 'grch37',
chrom: '17',
pos: 41245466,
del: 'G',
ins: 'A',
userRepr: 'GRCh37-17-41245466-G-A'
})
).rejects.toThrow()
})
})

0 comments on commit d906879

Please sign in to comment.