Skip to content

Commit

Permalink
Change suse_credentials endpoint to suse_manager under settings
Browse files Browse the repository at this point in the history
  • Loading branch information
CDimonaco committed Jul 16, 2024
1 parent 6916b23 commit 2df1d35
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 69 deletions.
11 changes: 5 additions & 6 deletions assets/js/lib/api/softwareUpdatesSettings.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { networkClient } from '@lib/network';

export const getSettings = () =>
networkClient.get(`/settings/suma_credentials`);
export const getSettings = () => networkClient.get(`/settings/suse_manager`);

export const saveSettings = (settings) =>
networkClient.post(`/settings/suma_credentials`, settings);
networkClient.post(`/settings/suse_manager`, settings);

export const updateSettings = (settings) =>
networkClient.patch(`/settings/suma_credentials`, settings);
networkClient.patch(`/settings/suse_manager`, settings);

export const clearSettings = () =>
networkClient.delete(`/settings/suma_credentials`);
networkClient.delete(`/settings/suse_manager`);

export const testConnection = () =>
networkClient.post(`/settings/suma_credentials/test`);
networkClient.post(`/settings/suse_manager/test`);
2 changes: 1 addition & 1 deletion assets/js/state/sagas/hosts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe('Hosts sagas', () => {

const settingsResponse = softwareUpdatesSettingsFactory.build();

axiosMock.onGet('/settings/suma_credentials').reply(200, settingsResponse);
axiosMock.onGet('/settings/suse_manager').reply(200, settingsResponse);

const softwareUpdatesResponse = {
relevant_patches: [
Expand Down
26 changes: 11 additions & 15 deletions assets/js/state/sagas/softwareUpdatesSettings.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ describe('Software Updates Settings saga', () => {
const axiosMock = new MockAdapter(networkClient);
const successfulResponse = softwareUpdatesSettingsFactory.build();

axiosMock
.onGet('/settings/suma_credentials')
.reply(200, successfulResponse);
axiosMock.onGet('/settings/suse_manager').reply(200, successfulResponse);

const dispatched = await recordSaga(fetchSoftwareUpdatesSettings);

Expand All @@ -46,7 +44,7 @@ describe('Software Updates Settings saga', () => {
it('should empty software updates settings when no configured settings were found', async () => {
const axiosMock = new MockAdapter(networkClient);

axiosMock.onGet('/settings/suma_credentials').reply(404);
axiosMock.onGet('/settings/suse_manager').reply(404);

const dispatched = await recordSaga(fetchSoftwareUpdatesSettings);

Expand All @@ -60,7 +58,7 @@ describe('Software Updates Settings saga', () => {
'should empty software updates settings and put a network error flag on failed fetching',
async (status) => {
const axiosMock = new MockAdapter(networkClient);
axiosMock.onGet('/settings/suma_credentials').reply(status);
axiosMock.onGet('/settings/suse_manager').reply(status);

const dispatched = await recordSaga(fetchSoftwareUpdatesSettings);

Expand Down Expand Up @@ -89,9 +87,7 @@ describe('Software Updates Settings saga', () => {
ca_uploaded_at: caUploadedAt,
});

axiosMock
.onPost('/settings/suma_credentials')
.reply(201, successfulResponse);
axiosMock.onPost('/settings/suse_manager').reply(201, successfulResponse);

const dispatched = await recordSaga(saveSoftwareUpdatesSettings, {
payload,
Expand Down Expand Up @@ -126,7 +122,7 @@ describe('Software Updates Settings saga', () => {
},
];

axiosMock.onPost('/settings/suma_credentials', payload).reply(422, {
axiosMock.onPost('/settings/suse_manager', payload).reply(422, {
errors,
});

Expand Down Expand Up @@ -158,7 +154,7 @@ describe('Software Updates Settings saga', () => {
});

axiosMock
.onPatch('/settings/suma_credentials')
.onPatch('/settings/suse_manager')
.reply(200, successfulResponse);

const dispatched = await recordSaga(
Expand Down Expand Up @@ -200,7 +196,7 @@ describe('Software Updates Settings saga', () => {
},
];

axiosMock.onPatch('/settings/suma_credentials', payload).reply(422, {
axiosMock.onPatch('/settings/suse_manager', payload).reply(422, {
errors,
});

Expand All @@ -219,7 +215,7 @@ describe('Software Updates Settings saga', () => {
it('should successfully clear software updates settings', async () => {
const axiosMock = new MockAdapter(networkClient);

axiosMock.onDelete('/settings/suma_credentials').reply(204);
axiosMock.onDelete('/settings/suse_manager').reply(204);

const dispatched = await recordSaga(clearSoftwareUpdatesSettings);

Expand All @@ -236,7 +232,7 @@ describe('Software Updates Settings saga', () => {
{ detail: 'Something went wrong.', title: 'Internal Server Error' },
];

axiosMock.onDelete('/settings/suma_credentials').reply(500, {
axiosMock.onDelete('/settings/suse_manager').reply(500, {
errors,
});

Expand All @@ -253,7 +249,7 @@ describe('Software Updates Settings saga', () => {
it('should notify on successful connection test', async () => {
const axiosMock = new MockAdapter(networkClient);

axiosMock.onPost('/settings/suma_credentials/test').reply(200);
axiosMock.onPost('/settings/suse_manager/test').reply(200);

const dispatched = await recordSaga(testSoftwareUpdatesConnection);

Expand All @@ -269,7 +265,7 @@ describe('Software Updates Settings saga', () => {
async (errorStatus) => {
const axiosMock = new MockAdapter(networkClient);

axiosMock.onPost('/settings/suma_credentials/test').reply(errorStatus);
axiosMock.onPost('/settings/suse_manager/test').reply(errorStatus);

const dispatched = await recordSaga(testSoftwareUpdatesConnection);

Expand Down
6 changes: 3 additions & 3 deletions lib/trento_web/controllers/v1/settings_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ defmodule TrentoWeb.V1.SettingsController do
@spec get_suse_manager_settings(Plug.Conn.t(), any) :: Plug.Conn.t()
def get_suse_manager_settings(conn, _) do
with {:ok, settings} <- Settings.get_suse_manager_settings() do
render(conn, "suma_credentials.json", %{settings: settings})
render(conn, "suse_manager.json", %{settings: settings})
end
end

Expand All @@ -187,7 +187,7 @@ defmodule TrentoWeb.V1.SettingsController do
with {:ok, saved_settings} <- Settings.save_suse_manager_settings(settings_params) do
conn
|> put_status(:created)
|> render("suma_credentials.json", %{settings: saved_settings})
|> render("suse_manager.json", %{settings: saved_settings})
end
end

Expand All @@ -211,7 +211,7 @@ defmodule TrentoWeb.V1.SettingsController do
with {:ok, saved_settings} <- Settings.change_suse_manager_settings(update_settings_paylod) do
conn
|> put_status(:ok)
|> render("suma_credentials.json", %{settings: saved_settings})
|> render("suse_manager.json", %{settings: saved_settings})
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/trento_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ defmodule TrentoWeb.Router do
get "/activity_log", SettingsController, :get_activity_log_settings

if Application.compile_env!(:trento, :suse_manager_enabled) do
scope "/suma_credentials" do
scope "/suse_manager" do
get "/", SettingsController, :get_suse_manager_settings
post "/", SettingsController, :save_suse_manager_settings
patch "/", SettingsController, :update_suse_manager_settings
Expand Down
2 changes: 1 addition & 1 deletion lib/trento_web/views/v1/settings_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule TrentoWeb.V1.SettingsView do
}
end

def render("suma_credentials.json", %{
def render("suse_manager.json", %{
settings: %{
url: url,
username: username,
Expand Down
32 changes: 14 additions & 18 deletions test/e2e/cypress/e2e/settings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ context('Settings page', () => {

before(() => {
cy.reload();
cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
cy.intercept('GET', '/api/v1/settings/suse_manager').as(
'getSettings'
);
cy.wait('@getSettings');
Expand All @@ -213,7 +213,7 @@ context('Settings page', () => {
cy.get(`[name="${name}"]`).type(value, { delay: 0 });
});

cy.intercept('POST', '/api/v1/settings/suma_credentials').as(
cy.intercept('POST', '/api/v1/settings/suse_manager').as(
'saveSettings'
);
cy.get('button').contains('Save Settings').click();
Expand Down Expand Up @@ -272,7 +272,7 @@ context('Settings page', () => {
cy.get(`[name="${name}"]`).type(value, { delay: 0 });
});

cy.intercept('POST', '/api/v1/settings/suma_credentials').as(
cy.intercept('POST', '/api/v1/settings/suse_manager').as(
'saveSettings'
);
cy.get('button').contains('Save Settings').click();
Expand Down Expand Up @@ -318,7 +318,7 @@ context('Settings page', () => {
it(`should show settings edit form. Scenario: ${name}`, () => {
cy.saveSUMASettings(settings);
cy.reload();
cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
cy.intercept('GET', '/api/v1/settings/suse_manager').as(
'getSettings'
);
cy.wait('@getSettings');
Expand Down Expand Up @@ -410,7 +410,7 @@ context('Settings page', () => {
};
cy.saveSUMASettings(initialSettings);
cy.reload();
cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
cy.intercept('GET', '/api/v1/settings/suse_manager').as(
'getSettings'
);
cy.wait('@getSettings');
Expand All @@ -425,7 +425,7 @@ context('Settings page', () => {
newValues.forEach(({ name, value }) => {
cy.get(`[name="${name}"]`).clear().type(value, { delay: 0 });
});
cy.intercept('PATCH', '/api/v1/settings/suma_credentials').as(
cy.intercept('PATCH', '/api/v1/settings/suse_manager').as(
'changeSettings'
);
cy.get('button').contains('Save Settings').click();
Expand Down Expand Up @@ -534,7 +534,7 @@ context('Settings page', () => {
it(`should change settings: ${name}`, () => {
cy.saveSUMASettings(initialSettings);
cy.reload();
cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
cy.intercept('GET', '/api/v1/settings/suse_manager').as(
'getSettings'
);
cy.wait('@getSettings');
Expand All @@ -549,7 +549,7 @@ context('Settings page', () => {
newValues.forEach(({ name, value }) => {
cy.get(`[name="${name}"]`).clear().type(value, { delay: 0 });
});
cy.intercept('PATCH', '/api/v1/settings/suma_credentials').as(
cy.intercept('PATCH', '/api/v1/settings/suse_manager').as(
'changeSettings'
);
cy.get('button').contains('Save Settings').click();
Expand Down Expand Up @@ -583,9 +583,7 @@ context('Settings page', () => {
ca_cert: validCertificate,
});
cy.reload();
cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
'getSettings'
);
cy.intercept('GET', '/api/v1/settings/suse_manager').as('getSettings');
cy.wait('@getSettings');

cy.get('[aria-label="suma-url"]').should('contain', sumaUrl);
Expand All @@ -596,7 +594,7 @@ context('Settings page', () => {
cy.get('[aria-label="suma-username"]').should('contain', sumaUsername);
cy.get('[aria-label="suma-password"]').should('contain', '•••••');

cy.intercept('DELETE', '/api/v1/settings/suma_credentials').as(
cy.intercept('DELETE', '/api/v1/settings/suse_manager').as(
'deleteSUMASettings'
);
cy.get('[aria-label="clear-suma-settings"]').click();
Expand All @@ -613,17 +611,15 @@ context('Settings page', () => {
cy.clearSUMASettings();
cy.reload();

cy.intercept('GET', '/api/v1/settings/suma_credentials').as(
'getSettings'
);
cy.intercept('GET', '/api/v1/settings/suse_manager').as('getSettings');
cy.wait('@getSettings');

cy.get('[aria-label="suma-url"]').should('have.text', 'https://');
cy.get('[aria-label="suma-cacert-upload-date"]').should('contain', '-');
cy.get('[aria-label="suma-username"]').should('contain', '.....');
cy.get('[aria-label="suma-password"]').should('contain', '.....');

cy.intercept('DELETE', '/api/v1/settings/suma_credentials').as(
cy.intercept('DELETE', '/api/v1/settings/suse_manager').as(
'deleteSUMASettings'
);
cy.get('[aria-label="clear-suma-settings"]').click();
Expand Down Expand Up @@ -657,7 +653,7 @@ context('Settings page', () => {
});

it('should succeed', () => {
cy.intercept('POST', '/api/v1/settings/suma_credentials/test', {
cy.intercept('POST', '/api/v1/settings/suse_manager/test', {
statusCode: 200,
}).as('testConnection');

Expand All @@ -667,7 +663,7 @@ context('Settings page', () => {
});

it('should fail', () => {
cy.intercept('POST', '/api/v1/settings/suma_credentials/test', {
cy.intercept('POST', '/api/v1/settings/suse_manager/test', {
statusCode: 422,
}).as('testConnection');

Expand Down
4 changes: 2 additions & 2 deletions test/e2e/cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ Cypress.Commands.add(
({ url, username, password, ca_cert }) =>
cy.apiLogin().then(({ accessToken }) =>
cy.request({
url: '/api/v1/settings/suma_credentials',
url: '/api/v1/settings/suse_manager',
method: 'POST',
auth: {
bearer: accessToken,
Expand All @@ -267,7 +267,7 @@ Cypress.Commands.add(
Cypress.Commands.add('clearSUMASettings', () =>
cy.apiLogin().then(({ accessToken }) =>
cy.request({
url: '/api/v1/settings/suma_credentials',
url: '/api/v1/settings/suse_manager',
method: 'DELETE',
auth: {
bearer: accessToken,
Expand Down
Loading

0 comments on commit 2df1d35

Please sign in to comment.