Skip to content

Commit

Permalink
test: adds tests for study store
Browse files Browse the repository at this point in the history
  • Loading branch information
svituz committed Mar 12, 2024
1 parent 1705597 commit 566f4f3
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 2 deletions.
70 changes: 70 additions & 0 deletions tests/unit/specs/mockData.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,73 @@ export const mockCollectionResponse = {
}
}]
}

export const mockStudyResponse = {
id: 's-001',
title: 'Important study',
description: 'An important clinical study',
type: 'Observational',
age_unit: [
{
_href: '/api/v2/eu_bbmri_eric_age_units/YEAR',
id: 'YEAR',
label: 'Year'
}
],
also_known: [
{
_href: '/api/v2/eu_bbmri_eric_also_known_in/s001-aka-cs-001',
id: 'id:001',
name_system: 'Another catalog',
pid: 'cs-001',
url: 'https://another-catalog.eu/study/cs-001',
withdrawn: false,
label: 'Another Catalog'
}
],
collections: [
{
id: 'c-001',
name: 'beautiful collection',
description: 'beautiful samples',
order_of_magnitude: {
_href: '/api/v2/eu_bbmri_eric_biobank_size/3',
size: '777'
},
country: {
name: 'Genovia'
},
network: [
{
id: 'network-x',
name: 'Network x'
},
{
id: 'network-y',
name: 'Network y'
}
],
biobank: {
id: 'b-001',
name: 'beautiful biobank',
juridical_person: 'Is this even a person?',
email: '[email protected]',
url: 'https://beautiful-biobank.gnv'
}
}
],
age_low: 16,
number_of_subjects: 373,
sex: [
{
_href: '/api/v2/eu_bbmri_eric_sex_types/MALE',
id: 'MALE',
label: 'Male'
},
{
_href: '/api/v2/eu_bbmri_eric_sex_types/FEMALE',
id: 'FEMALE',
label: 'Female'
}
]
}
38 changes: 36 additions & 2 deletions tests/unit/specs/store/actions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ describe('store', () => {
const response = {
page: { totalElements: 2 }
}

api.get.mockResolvedValueOnce(response)

const filterName = 'country'
Expand All @@ -302,7 +302,7 @@ describe('store', () => {
})

it('should not call SetFIlterLoading if the constructed query url equals the last constructed query url for the same filter', async () => {

const filterName = 'country'
const activeFilters = {'materials' : ['DNA']}
state.filterOptionDictionary = mockFilterOptionDictionary
Expand All @@ -324,4 +324,38 @@ describe('store', () => {
expect(commit).toBeCalledWith('SetError', filterReductionError)
})
})

describe('GetStudyReport', () => {
it('should retrieve a single study entity from the server based on a study id and store it in the state', async () => {
const response = {
_meta: {
name: 'meta'
},
id: 's-001',
name: 'beautiful study',
description: 'beautiful study'
}

api.get.mockResolvedValueOnce(response)
const studyId = 's-001'

await actions.GetStudyReport({ commit, state }, studyId)
expect(api.get).toHaveBeenLastCalledWith(`/api/v2/eu_bbmri_eric_studies/${studyId}?attrs=*,collections(*),also_known(*)`)
expect(commit).toHaveBeenNthCalledWith(1, 'SetLoading', true)
expect(commit).toHaveBeenNthCalledWith(2, 'SetStudyReport', response)
expect(commit).toHaveBeenNthCalledWith(3, 'SetLoading', false)
})

it('should set an error if the server respond with an error', async () => {
const studyId = 's-001'
const error = new Error('Error from server')
api.get.mockRejectedValue(error)

await actions.GetStudyReport({ commit, state }, studyId)

expect(commit).toHaveBeenNthCalledWith(1, 'SetLoading', true)
expect(commit).toHaveBeenNthCalledWith(2, 'SetError', error)
expect(commit).toHaveBeenNthCalledWith(3, 'SetLoading', false)
})
})
})
13 changes: 13 additions & 0 deletions tests/unit/specs/store/study/studyMutations.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { studyMutations } from '@/store/study/studyMutations'
import { mockStudyResponse, mockState } from '../../mockData'
let state

describe('Study mutations', () => {
beforeEach(() => {
state = mockState()
})

it('can SetStudyReport', () => {
studyMutations.SetStudyReport(state, mockStudyResponse)
})
})

0 comments on commit 566f4f3

Please sign in to comment.