Skip to content

Commit

Permalink
Fix PATCH/DELETE calls (#1204)
Browse files Browse the repository at this point in the history
Performing DELETE/PATCH calls were not working correctly because the URL
was wrong. It does not happen in development if you are using the proxy.
  • Loading branch information
imobachgs authored May 14, 2024
2 parents 6738927 + 95b1c47 commit 2fe4142
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions web/package/agama-web-ui.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue May 14 11:17:45 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

- Fix DELETE and PATCH calls in the HTTPClient
(gh#openSUSE/agama#1204).

-------------------------------------------------------------------
Mon May 13 09:01:29 UTC 2024 - Imobach Gonzalez Sosa <[email protected]>

Expand Down
4 changes: 2 additions & 2 deletions web/src/client/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class HTTPClient {
* @return {Promise<Response>} Server response.
*/
async delete(url) {
const response = await fetch(`${this.baseUrl}/${url}`, {
const response = await fetch(`${this.baseUrl}${url}`, {
method: "DELETE",
});

Expand All @@ -158,7 +158,7 @@ class HTTPClient {
* @return {Promise<Response>} Server response.
*/
async patch(url, data) {
const response = await fetch(`${this.baseUrl}/${url}`, {
const response = await fetch(`${this.baseUrl}${url}`, {
method: "PATCH",
body: JSON.stringify(data),
headers: {
Expand Down
2 changes: 1 addition & 1 deletion web/src/client/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class UsersBaseClient {
* @return {Promise<boolean>} whether the operation was successful or not
*/
async setRootPassword(password) {
const response = await this.client.patch("/users/root", { password, password_encrypted: false });
const response = await this.client.patch("/users/root", { password, passwordEncrypted: false });
return response.ok;
}

Expand Down
8 changes: 4 additions & 4 deletions web/src/client/users.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ describe("#setRootPassword", () => {
const result = await client.setRootPassword("12345");
expect(mockPatchFn).toHaveBeenCalledWith("/users/root", {
password: "12345",
password_encrypted: false,
passwordEncrypted: false,
});
expect(result).toEqual(true);
});
Expand All @@ -183,7 +183,7 @@ describe("#setRootPassword", () => {
const result = await client.setRootPassword("12345");
expect(mockPatchFn).toHaveBeenCalledWith("/users/root", {
password: "12345",
password_encrypted: false,
passwordEncrypted: false,
});
expect(result).toEqual(false);
});
Expand All @@ -199,7 +199,7 @@ describe("#removeRootPassword", () => {
const result = await client.removeRootPassword();
expect(mockPatchFn).toHaveBeenCalledWith("/users/root", {
password: "",
password_encrypted: false,
passwordEncrypted: false,
});
expect(result).toEqual(true);
});
Expand All @@ -213,7 +213,7 @@ describe("#removeRootPassword", () => {
const result = await client.removeRootPassword();
expect(mockPatchFn).toHaveBeenCalledWith("/users/root", {
password: "",
password_encrypted: false,
passwordEncrypted: false,
});
expect(result).toEqual(false);
});
Expand Down

0 comments on commit 2fe4142

Please sign in to comment.