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

Changes settings revert all to send DELETE on individual endpoint rather than PATCHing #10376

Merged
Merged
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
4 changes: 4 additions & 0 deletions awx/ui_next/src/api/models/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class Settings extends Base {
createTest(category, data) {
return this.http.post(`${this.baseUrl}${category}/test/`, data);
}

revertCategory(category) {
return this.http.delete(`${this.baseUrl}${category}/`);
}
}

export default Settings;

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion awx/ui_next/src/screens/Setting/ActivityStream/index.js

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ function AzureADEdit() {
null
);

const { error: revertError, request: revertAll } = useRequest(
useCallback(async () => {
await SettingsAPI.revertCategory('azuread-oauth2');
}, []),
null
);

const handleSubmit = async form => {
await submitForm({
...form,
Expand All @@ -68,13 +75,11 @@ function AzureADEdit() {
};

const handleRevertAll = async () => {
const defaultValues = Object.assign(
...Object.entries(azure).map(([key, value]) => ({
[key]: value.default,
}))
);
await submitForm(defaultValues);
await revertAll();

closeModal();

history.push('/settings/azure/details');
};

const handleCancel = () => {
Expand Down Expand Up @@ -120,6 +125,7 @@ function AzureADEdit() {
config={azure.SOCIAL_AUTH_AZUREAD_OAUTH2_TEAM_MAP}
/>
{submitError && <FormSubmitError error={submitError} />}
{revertError && <FormSubmitError error={revertError} />}
</FormColumnLayout>
<RevertFormActionGroup
onCancel={handleCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('<AzureADEdit />', () => {
let history;

beforeEach(() => {
SettingsAPI.revertCategory.mockResolvedValue({});
SettingsAPI.updateAll.mockResolvedValue({});
SettingsAPI.readCategory.mockResolvedValue({
data: {
Expand Down Expand Up @@ -60,7 +61,7 @@ describe('<AzureADEdit />', () => {
});

test('should successfully send default values to api on form revert all', async () => {
expect(SettingsAPI.updateAll).toHaveBeenCalledTimes(0);
expect(SettingsAPI.revertCategory).toHaveBeenCalledTimes(0);
expect(wrapper.find('RevertAllAlert')).toHaveLength(0);
await act(async () => {
wrapper
Expand All @@ -75,13 +76,8 @@ describe('<AzureADEdit />', () => {
.invoke('onClick')();
});
wrapper.update();
expect(SettingsAPI.updateAll).toHaveBeenCalledTimes(1);
expect(SettingsAPI.updateAll).toHaveBeenCalledWith({
SOCIAL_AUTH_AZUREAD_OAUTH2_KEY: '',
SOCIAL_AUTH_AZUREAD_OAUTH2_SECRET: '',
SOCIAL_AUTH_AZUREAD_OAUTH2_ORGANIZATION_MAP: null,
SOCIAL_AUTH_AZUREAD_OAUTH2_TEAM_MAP: null,
});
expect(SettingsAPI.revertCategory).toHaveBeenCalledTimes(1);
expect(SettingsAPI.revertCategory).toHaveBeenCalledWith('azuread-oauth2');
});

test('should successfully send request to api on form submission', async () => {
Expand Down
18 changes: 12 additions & 6 deletions awx/ui_next/src/screens/Setting/GitHub/GitHubEdit/GitHubEdit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ function GitHubEdit() {
null
);

const { error: revertError, request: revertAll } = useRequest(
useCallback(async () => {
await SettingsAPI.revertCategory('github');
}, []),
null
);

const handleSubmit = async form => {
await submitForm({
...form,
Expand All @@ -66,13 +73,11 @@ function GitHubEdit() {
};

const handleRevertAll = async () => {
const defaultValues = Object.assign(
...Object.entries(github).map(([key, value]) => ({
[key]: value.default,
}))
);
await submitForm(defaultValues);
await revertAll();

closeModal();

history.push('/settings/github/details');
};

const handleCancel = () => {
Expand Down Expand Up @@ -118,6 +123,7 @@ function GitHubEdit() {
config={github.SOCIAL_AUTH_GITHUB_TEAM_MAP}
/>
{submitError && <FormSubmitError error={submitError} />}
{revertError && <FormSubmitError error={revertError} />}
</FormColumnLayout>
<RevertFormActionGroup
onCancel={handleCancel}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ describe('<GitHubEdit />', () => {
let history;

beforeEach(() => {
SettingsAPI.revertCategory.mockResolvedValue({});
SettingsAPI.updateAll.mockResolvedValue({});
SettingsAPI.readCategory.mockResolvedValue({
data: {
Expand Down Expand Up @@ -72,7 +73,7 @@ describe('<GitHubEdit />', () => {
});

test('should successfully send default values to api on form revert all', async () => {
expect(SettingsAPI.updateAll).toHaveBeenCalledTimes(0);
expect(SettingsAPI.revertCategory).toHaveBeenCalledTimes(0);
expect(wrapper.find('RevertAllAlert')).toHaveLength(0);
await act(async () => {
wrapper
Expand All @@ -87,13 +88,8 @@ describe('<GitHubEdit />', () => {
.invoke('onClick')();
});
wrapper.update();
expect(SettingsAPI.updateAll).toHaveBeenCalledTimes(1);
expect(SettingsAPI.updateAll).toHaveBeenCalledWith({
SOCIAL_AUTH_GITHUB_KEY: '',
SOCIAL_AUTH_GITHUB_SECRET: '',
SOCIAL_AUTH_GITHUB_ORGANIZATION_MAP: null,
SOCIAL_AUTH_GITHUB_TEAM_MAP: null,
});
expect(SettingsAPI.revertCategory).toHaveBeenCalledTimes(1);
expect(SettingsAPI.revertCategory).toHaveBeenCalledWith('github');
});

test('should successfully send request to api on form submission', async () => {
Expand Down
Loading