-
Notifications
You must be signed in to change notification settings - Fork 15
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
Implement sagas for save and upsate of SUMA settings #2338
Merged
dottorblaster
merged 3 commits into
main
from
implement-sagas-suma-settings-save-update
Feb 20, 2024
Merged
Changes from 2 commits
Commits
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
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,3 +1,5 @@ | ||||||
import { faker } from '@faker-js/faker'; | ||||||
|
||||||
import { recordSaga } from '@lib/test-utils'; | ||||||
|
||||||
import { networkClient } from '@lib/network'; | ||||||
|
@@ -7,16 +9,20 @@ import { softwareUpdatesSettingsFactory } from '@lib/test-utils/factories/softwa | |||||
import { | ||||||
startLoadingSoftwareUpdatesSettings, | ||||||
setSoftwareUpdatesSettings, | ||||||
setSoftwareUpdatesSettingsErrors, | ||||||
setEmptySoftwareUpdatesSettings, | ||||||
} from '@state/softwareUpdatesSettings'; | ||||||
|
||||||
import { fetchSoftwareUpdatesSettings } from './softwareUpdatesSettings'; | ||||||
|
||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
import { | ||||||
fetchSoftwareUpdatesSettings, | ||||||
saveSoftwareUpdatesSettings, | ||||||
updateSoftwareUpdatesSettings, | ||||||
} from './softwareUpdatesSettings'; | ||||||
|
||||||
describe('Software Updates Settings saga', () => { | ||||||
describe('Fetching Software Updates Settings', () => { | ||||||
it('should successfully fetch software updates settings', async () => { | ||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
const successfulResponse = softwareUpdatesSettingsFactory.build(); | ||||||
|
||||||
axiosMock | ||||||
|
@@ -32,6 +38,7 @@ describe('Software Updates Settings saga', () => { | |||||
}); | ||||||
|
||||||
it('should empty software updates settings on failed fetching', async () => { | ||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
[404, 500].forEach(async (errorStatus) => { | ||||||
axiosMock.onGet('/settings/suma_credentials').reply(errorStatus); | ||||||
|
||||||
|
@@ -44,4 +51,134 @@ describe('Software Updates Settings saga', () => { | |||||
}); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('Saving Software Updates settings', () => { | ||||||
it('should successfully save software updates settings', async () => { | ||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
const payload = { | ||||||
url: faker.internet.url(), | ||||||
username: faker.word.noun(), | ||||||
password: faker.word.noun(), | ||||||
ca_cert: faker.lorem.text(), | ||||||
}; | ||||||
const caUploadedAt = faker.date.recent().toString(); | ||||||
const successfulResponse = softwareUpdatesSettingsFactory.build({ | ||||||
url: payload.url, | ||||||
username: payload.username, | ||||||
ca_uploaded_at: caUploadedAt, | ||||||
}); | ||||||
|
||||||
axiosMock | ||||||
.onPost('/settings/suma_credentials') | ||||||
.reply(201, successfulResponse); | ||||||
|
||||||
const dispatched = await recordSaga(saveSoftwareUpdatesSettings, payload); | ||||||
|
||||||
expect(dispatched).toEqual([ | ||||||
startLoadingSoftwareUpdatesSettings(), | ||||||
setSoftwareUpdatesSettings(successfulResponse), | ||||||
]); | ||||||
}); | ||||||
|
||||||
it('should have errors on failed saving', async () => { | ||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
const payload = { | ||||||
url: '', | ||||||
username: '', | ||||||
password: faker.word.noun(), | ||||||
ca_cert: '', | ||||||
}; | ||||||
const errors = [ | ||||||
{ | ||||||
detail: "can't be blank", | ||||||
source: { pointer: '/url' }, | ||||||
title: 'Invalid value', | ||||||
}, | ||||||
{ | ||||||
detail: "can't be blank", | ||||||
source: { pointer: '/ca_cert' }, | ||||||
title: 'Invalid value', | ||||||
}, | ||||||
]; | ||||||
|
||||||
axiosMock.onPost('/settings/suma_credentials', payload).reply(422, { | ||||||
errors, | ||||||
}); | ||||||
|
||||||
const dispatched = await recordSaga(saveSoftwareUpdatesSettings, payload); | ||||||
|
||||||
expect(dispatched).toEqual([ | ||||||
startLoadingSoftwareUpdatesSettings(), | ||||||
setSoftwareUpdatesSettingsErrors(errors), | ||||||
]); | ||||||
}); | ||||||
}); | ||||||
|
||||||
describe('Updating Software Updates settings', () => { | ||||||
it('should successfully save software updates settings', async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a copy/pasta from previous test
Suggested change
|
||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
const payload = { | ||||||
url: faker.internet.url(), | ||||||
username: faker.word.noun(), | ||||||
password: faker.word.noun(), | ||||||
ca_cert: faker.lorem.text(), | ||||||
}; | ||||||
const caUploadedAt = faker.date.recent().toString(); | ||||||
const successfulResponse = softwareUpdatesSettingsFactory.build({ | ||||||
url: payload.url, | ||||||
username: payload.username, | ||||||
ca_uploaded_at: caUploadedAt, | ||||||
}); | ||||||
|
||||||
axiosMock | ||||||
.onPatch('/settings/suma_credentials') | ||||||
.reply(200, successfulResponse); | ||||||
|
||||||
const dispatched = await recordSaga( | ||||||
updateSoftwareUpdatesSettings, | ||||||
payload | ||||||
); | ||||||
|
||||||
expect(dispatched).toEqual([ | ||||||
startLoadingSoftwareUpdatesSettings(), | ||||||
setSoftwareUpdatesSettings(successfulResponse), | ||||||
]); | ||||||
}); | ||||||
|
||||||
it('should have errors on failed saving', async () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
const axiosMock = new MockAdapter(networkClient); | ||||||
const payload = { | ||||||
url: '', | ||||||
username: '', | ||||||
password: faker.word.noun(), | ||||||
ca_cert: '', | ||||||
}; | ||||||
const errors = [ | ||||||
{ | ||||||
detail: "can't be blank", | ||||||
source: { pointer: '/url' }, | ||||||
title: 'Invalid value', | ||||||
}, | ||||||
{ | ||||||
detail: "can't be blank", | ||||||
source: { pointer: '/ca_cert' }, | ||||||
title: 'Invalid value', | ||||||
}, | ||||||
]; | ||||||
|
||||||
axiosMock.onPatch('/settings/suma_credentials', payload).reply(422, { | ||||||
errors, | ||||||
}); | ||||||
|
||||||
const dispatched = await recordSaga( | ||||||
updateSoftwareUpdatesSettings, | ||||||
payload | ||||||
); | ||||||
|
||||||
expect(dispatched).toEqual([ | ||||||
startLoadingSoftwareUpdatesSettings(), | ||||||
setSoftwareUpdatesSettingsErrors(errors), | ||||||
]); | ||||||
}); | ||||||
}); | ||||||
}); |
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
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.
OCD alert: mismatching errors based on the input.
Providing an empty username
username: '',
would result in an extra error besides url/ca_cert.Feel free to keep like this, tho 😄 The test still tests what it's supposed to test.