Skip to content

Commit

Permalink
fix(web): drop dead code at product client (#1498)
Browse files Browse the repository at this point in the history
Drop dead code that was replaced by its equivalent using TanStack Query.
See #1454.
  • Loading branch information
imobachgs authored Jul 25, 2024
2 parents 87b5100 + 96f1da7 commit 4935eed
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 73 deletions.
50 changes: 0 additions & 50 deletions web/src/client/software.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,56 +95,6 @@ class ProductClient {
this.client = client;
}

/**
* Returns the list of available products.
*
* @return {Promise<Array<Product>>}
*/
async getAll() {
const response = await this.client.get("/software/products");
if (!response.ok) {
console.log("Failed to get software products: ", response);
}
return response.json();
}

/**
* Returns the identifier of the selected product.
*
* @return {Promise<string>} Selected identifier.
*/
async getSelected() {
const response = await this.client.get("/software/config");
if (!response.ok) {
console.log("Failed to get software config: ", response);
}
const config = await response.json();
return config.product;
}

/**
* Selects a product for installation.
*
* @param {string} id - Product ID.
*/
async select(id) {
await this.client.put("/software/config", { product: id });
}

/**
* Registers a callback to run when the select product changes.
*
* @param {(id: string) => void} handler - Callback function.
* @return {import ("./http").RemoveFn} Function to remove the callback.
*/
onChange(handler) {
return this.client.onEvent("ProductChanged", ({ id }) => {
if (id) {
handler(id);
}
});
}

/**
* Returns the registration of the selected product.
*
Expand Down
23 changes: 0 additions & 23 deletions web/src/client/software.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,29 +74,6 @@ const microos = {
};

describe("ProductClient", () => {
describe("#getAll", () => {
it("returns the list of available products", async () => {
const http = new HTTPClient(new URL("http://localhost"));
const client = new ProductClient(http);
mockJsonFn.mockResolvedValue([tumbleweed, microos]);
const products = await client.getAll();
expect(products).toEqual([
{ id: "Tumbleweed", name: "openSUSE Tumbleweed", description: "Tumbleweed is..." },
{ id: "MicroOS", name: "openSUSE MicroOS", description: "MicroOS is..." },
]);
});
});

describe("#getSelected", () => {
it("returns the selected product", async () => {
const http = new HTTPClient(new URL("http://localhost"));
const client = new ProductClient(http);
mockJsonFn.mockResolvedValue({ product: "microos" });
const selected = await client.getSelected();
expect(selected).toEqual("microos");
});
});

describe("#getRegistration", () => {
describe("if the product is not registered yet", () => {
it("returns the expected registration result", async () => {
Expand Down

0 comments on commit 4935eed

Please sign in to comment.