-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from LCOGT/update/populateinstruments
Update/populateinstruments
- Loading branch information
Showing
5 changed files
with
119 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { vi, describe, it, expect, beforeEach } from 'vitest' | ||
import { getFilterList } from '../../../utils/populateInstrumentsUtils.js' | ||
import { fetchApiCall } from '../../../utils/api.js' | ||
import { createTestStores } from '../../../utils/testUtils' | ||
|
||
vi.mock('@/utils/api.js', () => ({ | ||
fetchApiCall: vi.fn() | ||
})) | ||
|
||
describe('thumbnailsUtils.js', () => { | ||
let configurationStore | ||
|
||
beforeEach(() => { | ||
const { configurationStore: store } = createTestStores() | ||
configurationStore = store | ||
fetchApiCall.mockClear() | ||
}) | ||
|
||
describe('getFilterList', () => { | ||
beforeEach(() => { | ||
fetchApiCall.mockClear() | ||
}) | ||
|
||
it('fetches instruments and returns schedulable filters', async () => { | ||
// Mock API response | ||
fetchApiCall.mockResolvedValueOnce({ | ||
'0M4-SCICAM-QHY600': { | ||
class: '0m4', | ||
optical_elements: { | ||
filters: [ | ||
{ name: 'Filter A', code: 'FA', schedulable: true }, | ||
{ name: 'Filter B', code: 'FB', schedulable: false } | ||
] | ||
} | ||
}, | ||
'0M4-SCICAM-FLI': { | ||
class: '0m4', | ||
optical_elements: { | ||
filters: [ | ||
{ name: 'Filter D', code: 'FD', schedulable: true }, | ||
{ name: 'Filter E', code: 'FE', schedulable: true } | ||
] | ||
} | ||
}, | ||
// This instrument should be ignored | ||
'1M0-SCICAM': { | ||
class: '1m0', | ||
optical_elements: { | ||
filters: [ | ||
{ name: 'Filter X', code: 'FX', schedulable: true } | ||
] | ||
} | ||
} | ||
}) | ||
|
||
const result = await getFilterList() | ||
|
||
expect(result).toEqual([ | ||
{ name: 'Filter A', code: 'FA' }, | ||
{ name: 'Filter D', code: 'FD' }, | ||
{ name: 'Filter E', code: 'FE' } | ||
]) | ||
|
||
expect(fetchApiCall).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
url: expect.stringContaining('instruments'), | ||
method: 'GET' | ||
}) | ||
) | ||
}) | ||
|
||
it('returns an empty array if no schedulable filters are found', async () => { | ||
fetchApiCall.mockResolvedValueOnce({ | ||
'0M4-SCICAM-QHY600': { | ||
class: '0m4', | ||
optical_elements: { | ||
filters: [ | ||
{ name: 'Filter A', code: 'FA', schedulable: false } | ||
] | ||
} | ||
} | ||
}) | ||
|
||
const result = await getFilterList() | ||
|
||
expect(result).toEqual([]) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { fetchApiCall } from './api.js' | ||
import { useConfigurationStore } from '../stores/configuration.js' | ||
|
||
export const getFilterList = async () => { | ||
const configurationStore = useConfigurationStore() | ||
const response = await fetchApiCall({ | ||
url: `${configurationStore.observationPortalUrl}instruments`, | ||
method: 'GET' | ||
}) | ||
const filterList = [] | ||
if (!response) { | ||
return filterList | ||
} | ||
const instrumentClass = '0m4' | ||
Object.values(response).forEach((instrument) => { | ||
if (instrument.class === instrumentClass && instrument.optical_elements.filters) { | ||
const schedulableFilters = instrument.optical_elements.filters | ||
.filter(filter => filter.schedulable) | ||
.map(filter => ({ name: filter.name, code: filter.code })) | ||
filterList.push(...schedulableFilters) | ||
} | ||
}) | ||
return filterList | ||
} |