Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Y24-338 - Pacbio libraries store migration from axios to native fetch #2011

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/stores/pacbioLibraries.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
*/
requests: {},
/**
* @property {Object} libraryTags - An object to store all tags from all libraries indexed by id.
* @property {Object} tags - An object to store all tags from all libraries indexed by id.
*/
libraryTags: {},
tags: {},
}),

getters: {
/**
* Transforms the libraries in the state into an array with additional properties.
*
* @function librariesArray
* @param {Object} state - The state object containing libraries, libraryTags, requests, and tubes.
* @param {Object} state - The state object containing libraries, tags, requests, and tubes.
* @returns {Array<Object>} - An array of library objects, each with id, tag_group_id, sample_name, barcode, and other attributes.
*/
librariesArray: (state) => {
Expand All @@ -67,15 +67,15 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {

/*Get the tag group ID from the library's tag ID or from the tag in pacbioRoot store(where all pacbio tags are kept). Why is this required?
The librariesArray is called in multiple places (in create and edit context) to get the libraries.
Therefore, librariesArray needs to search for the tag first in libraryTags.
Therefore, librariesArray needs to search for the tag first in tags.
If not found, it should then look for it in 'pacbioRoot' store tags.
It's important to note that 'pacbioRoot' store tags will only get populated if a 'pacbioRoot' store action fetchPacbioTagSets is called before,
which may not happen in all the places where it's called.
Hence, a search in both places is required to ensure that librariesArray returns the correct tag
associated with all libraries."*/

const tagGroupId = state.libraryTags[tagId]
? state.libraryTags[tagId].group_id
const tagGroupId = state.tags[tagId]
? state.tags[tagId].group_id
: pacbioRootStore.tags[tagId]
? pacbioRootStore.tags[tagId].group_id
: ''
Expand All @@ -102,25 +102,32 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
* @example
* await createLibraryInTraction(library, tagId);
*/
async createLibraryInTraction(library) {
async createLibraryInTraction({
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
sample: { id: pacbio_request_id },
}) {
const rootState = useRootStore()
const request = rootState.api.v1.traction.pacbio.libraries
const body = {
data: {
type: 'libraries',
attributes: {
pacbio_request_id: library.sample.id,
template_prep_kit_box_barcode: library.template_prep_kit_box_barcode,
tag_id: library.tag_id,
concentration: library.concentration,
volume: library.volume,
insert_size: library.insert_size,
pacbio_request_id,
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
primary_aliquot_attributes: {
template_prep_kit_box_barcode: library.template_prep_kit_box_barcode,
volume: library.volume,
concentration: library.concentration,
insert_size: library.insert_size,
tag_id: library.tag_id,
template_prep_kit_box_barcode,
tag_id,
concentration,
volume,
insert_size,
},
},
},
Expand Down Expand Up @@ -157,7 +164,7 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
* @param {number} page - The page number to fetch from the server.
* @returns {Promise<{success: boolean, errors: Array}>} - A promise that resolves to an object containing a success boolean and an array of errors.
*/
async fetchLibraries(filter, page) {
async fetchLibraries(filter = {}, page = {}) {
const rootStore = useRootStore()
const pacbioLibraries = rootStore.api.v1.traction.pacbio.libraries
const promise = pacbioLibraries.get({
Expand All @@ -173,7 +180,7 @@ export const usePacbioLibrariesStore = defineStore('pacbioLibraries', {
const { tubes, tags, requests } = groupIncludedByResource(included)
this.libraries = dataToObjectById({ data, includeRelationships: true })
this.tubes = dataToObjectById({ data: tubes })
this.libraryTags = dataToObjectById({ data: tags })
this.tags = dataToObjectById({ data: tags })
this.requests = dataToObjectById({ data: requests })
}
return { success, errors, meta }
Expand Down
72 changes: 72 additions & 0 deletions tests/factories/PacbioLibraryFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import BaseFactory from './BaseFactory.js'

/*
* Factory for creating a pacbio library
* @returns a base factory object with the runs data
*/
const PacbioLibraryFactory = () => {
const data = {
data: [
{
id: '1',
type: 'libraries',
attributes: {
state: 'pending',
volume: 1.0,
concentration: 1.0,
template_prep_kit_box_barcode: 'LK12345',
insert_size: 100,
created_at: '09/23/2019 11:18',
source_identifier: 'DN1:A1',
},
relationships: {
request: {
data: {
type: 'requests',
id: '1',
},
},
tag: {
data: {
type: 'tags',
id: '3',
},
},
tube: {
data: {
type: 'tubes',
id: '4',
},
},
},
},
],
included: [
{
id: '1',
type: 'requests',
attributes: {
sample_name: '4616STDY7535900',
},
},
{
id: '4',
type: 'tubes',
attributes: {
barcode: 'TRAC-2-721',
},
},
{
id: '3',
type: 'tags',
attributes: {
group_id: '1234',
},
},
],
}

return BaseFactory(data)
}

export default PacbioLibraryFactory
8 changes: 4 additions & 4 deletions tests/unit/store/traction/ont/pools/actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import actions from '@/store/traction/ont/pools/actions'
import actions from '@/store/traction/ont/pools/actions.js'
import { describe, expect, it } from 'vitest'
import defaultState from '@/store/traction/ont/pools/state'
import { payload } from '@/store/traction/ont/pools/pool'
import defaultState from '@/store/traction/ont/pools/state.js'
import { payload } from '@/store/traction/ont/pools/pool.js'
import OntTagSetFactory from '@tests/factories/OntTagSetFactory.js'
import OntRequestFactory from '@tests/factories/OntRequestFactory.js'
import OntPoolFactory from '@tests/factories/OntPoolFactory.js'
import OntPlateFactory from '@tests/factories/OntPlateFactory.js'
import OntTubeFactory from '@tests/factories/OntTubeFactory.js'
import OntAutoTagFactory from '../../../../../factories/OntAutoTagFactory'
import OntAutoTagFactory from '@tests/factories/OntAutoTagFactory.js'

const ontTagSetFactory = OntTagSetFactory()
const ontRequestFactory = OntRequestFactory()
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/store/traction/saphyr/tubes/actions.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Actions from '@/store/traction/saphyr/tubes/actions'
import * as Actions from '@/store/traction/saphyr/tubes/actions.js'
import SaphyrTubesFactory from '@tests/factories/SaphyrTubesFactory.js'
import BaseFactory from '../../../../../factories/BaseFactory'
import BaseFactory from '../../../../../factories/BaseFactory.js'

const saphyrTubesRequestFactory = SaphyrTubesFactory('request')
const saphyrTubesLibraryFactory = SaphyrTubesFactory('library')
Expand Down
11 changes: 8 additions & 3 deletions tests/unit/stores/pacbioLibraries.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { Data, createPinia, setActivePinia } from '@support/testHelper.js'
import { usePacbioLibrariesStore } from '@/stores/pacbioLibraries.js'
import { newResponse } from '@/api/v1/ResponseHelper.js'
import { beforeEach, describe, expect } from 'vitest'
// import PacbioLibraryFactory from '@tests/factories/PacbioLibraryFactory.js'

// const pacbioLibraryFactory = PacbioLibraryFactory()

describe('usePacbioLibrariesStore', () => {
beforeEach(() => {
/*Creates a fresh pinia instance and make it active so it's automatically picked
Expand All @@ -24,6 +28,7 @@ describe('usePacbioLibrariesStore', () => {
expect(store.libraries).toEqual(libraries)
})
})

describe('getters', () => {
it('returns libraries array from "state.libraries"', async () => {
const store = usePacbioLibrariesStore()
Expand Down Expand Up @@ -51,7 +56,7 @@ describe('usePacbioLibrariesStore', () => {
barcode: 'TRAC-2-721',
},
}
const libraryTags = {
const tags = {
3: {
id: '3',
type: 'tags',
Expand All @@ -66,7 +71,7 @@ describe('usePacbioLibrariesStore', () => {
},
}

store.$state = { libraries, libraryTags, requests, tubes }
store.$state = { libraries, tags, requests, tubes }
const libraryArray = [
{
id: '1',
Expand Down Expand Up @@ -243,7 +248,7 @@ describe('usePacbioLibrariesStore', () => {
type: 'tubes',
barcode: 'TRAC-2-721',
})
expect(store.libraryTags[3]).toEqual({
expect(store.tags[3]).toEqual({
id: '3',
type: 'tags',
group_id: '1234',
Expand Down