-
Notifications
You must be signed in to change notification settings - Fork 0
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
Update/populateinstruments #106
Merged
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0165b80
adds getfilterlist utils
capetillo c8e0979
updates component to use the utils function to populate filter list
capetillo 07f66ae
Adds test for getfilterlist
capetillo 7a5e617
updates test to remove getfilterlist logic from this component test
capetillo 258cfcb
removes unused vars
capetillo 3e2c3b9
adds if statement
capetillo 0edd661
removes hard coded instrument class
capetillo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,20 @@ | ||
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 = [] | ||
Object.values(response).forEach((instrument) => { | ||
Check failure on line 11 in src/utils/populateInstrumentsUtils.js GitHub Actions / testUnhandled error
Check failure on line 11 in src/utils/populateInstrumentsUtils.js GitHub Actions / testUnhandled error
|
||
if (instrument.class === '0m4' && 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 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is probably fine for now, but if Wayne's telescopes are integrated they may be 0m35 or something different, and we generally would want to keep this easily adjustable. You could put it in a global at the top of the file, or read it from the public/config/config.json which we can set in the deployment at runtime!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oo I like that!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm intrigued by this
read it from the public/config/config.json which we can set in the deployment at runtime
. I'll be declaring it as a global config and ask you about that statement in person (or you can also explain here but I'm patient and willing to rewrite this when the time comes)