diff --git a/web/src/client/l10n.js b/web/src/client/l10n.js index e6b61f4c39..140842ee94 100644 --- a/web/src/client/l10n.js +++ b/web/src/client/l10n.js @@ -62,7 +62,7 @@ class L10nClient { async getUILocale() { const response = await this.client.get("/l10n/config"); if (!response.ok) { - console.log("Failed to get localizaation config: ", response); + console.error("Failed to get localization config: ", response); return ""; } const config = await response.json(); @@ -89,7 +89,7 @@ class L10nClient { async getUIKeymap() { const response = await this.client.get("/l10n/config"); if (!response.ok) { - console.log("Failed to get localizaation config: ", response); + console.error("Failed to get localizaation config: ", response); return ""; } const config = await response.json(); @@ -116,7 +116,7 @@ class L10nClient { async timezones() { const response = await this.client.get("/l10n/timezones"); if (!response.ok) { - console.log("Failed to get localizaation config: ", response); + console.error("Failed to get localizaation config: ", response); return []; } const timezones = await response.json(); @@ -153,7 +153,7 @@ class L10nClient { async locales() { const response = await this.client.get("/l10n/locales"); if (!response.ok) { - console.log("Failed to get localizaation config: ", response); + console.error("Failed to get localizaation config: ", response); return []; } const locales = await response.json(); @@ -191,7 +191,7 @@ class L10nClient { async keymaps() { const response = await this.client.get("/l10n/keymaps"); if (!response.ok) { - console.log("Failed to get localizaation config: ", response); + console.error("Failed to get localizaation config: ", response); return []; } const keymaps = await response.json(); @@ -269,7 +269,7 @@ class L10nClient { async getConfig() { const response = await this.client.get("/l10n/config"); if (!response.ok) { - console.log("Failed to get localization config: ", response); + console.error("Failed to get localization config: ", response); return {}; } return await response.json(); diff --git a/web/src/client/manager.js b/web/src/client/manager.js index ffe8eb51be..03c691d6cb 100644 --- a/web/src/client/manager.js +++ b/web/src/client/manager.js @@ -72,7 +72,7 @@ class ManagerBaseClient { async canInstall() { const response = await this.client.get("/manager/installer"); if (!response.ok) { - console.log("Failed to get installer config: ", response); + console.error("Failed to get installer config: ", response); return false; } const installer = await response.json(); @@ -97,7 +97,7 @@ class ManagerBaseClient { async getPhase() { const response = await this.client.get("/manager/installer"); if (!response.ok) { - console.log("Failed to get installer config: ", response); + console.error("Failed to get installer config: ", response); return 0; } const installer = await response.json(); @@ -133,7 +133,7 @@ class ManagerBaseClient { async useIguana() { const response = await this.client.get("/manager/installer"); if (!response.ok) { - console.log("Failed to get installer config: ", response); + console.error("Failed to get installer config: ", response); return false; } const installer = await response.json(); diff --git a/web/src/client/network.test.js b/web/src/client/network.test.js index 5834e08dde..aadbbcb345 100644 --- a/web/src/client/network.test.js +++ b/web/src/client/network.test.js @@ -68,6 +68,15 @@ const mockSettings = { networking_enabled: true } +const mockJsonFn = jest.fn(); + +const mockGetFn = jest.fn().mockImplementation(() => { + return { + ok: true, + json: mockJsonFn, + }; +}); + jest.mock("./http", () => { return { HTTPClient: jest.fn().mockImplementation(() => { @@ -78,14 +87,12 @@ jest.mock("./http", () => { }; }); -const mockGetFn = jest.fn(); - describe("NetworkClient", () => { describe("#connections", () => { it("returns the list of active connections from the adapter", async () => { const http = new HTTPClient(new URL(ADDRESS)); const client = new NetworkClient(http); - mockGetFn.mockResolvedValue([mockWiredConnection, mockWirelessConnection]); + mockJsonFn.mockResolvedValue([mockWiredConnection, mockWirelessConnection]); const connections = await client.connections(); const eth0 = connections.find(c => c.id === "eth0"); expect(eth0).toEqual(mockConnection); @@ -96,7 +103,7 @@ describe("NetworkClient", () => { it("returns the list of addresses", async () => { const http = new HTTPClient(new URL(ADDRESS)); const client = new NetworkClient(http); - mockGetFn.mockResolvedValue([mockWiredConnection, mockWirelessConnection]); + mockJsonFn.mockResolvedValue([mockWiredConnection, mockWirelessConnection]); const addresses = await client.addresses(); expect(addresses).toEqual([{ address: "192.168.122.100", prefix: 24 }]); }); @@ -107,7 +114,7 @@ describe("NetworkClient", () => { it("returns network general settings", async () => { const http = new HTTPClient(new URL(ADDRESS)); const client = new NetworkClient(http); - mockGetFn.mockResolvedValue(mockSettings); + mockJsonFn.mockResolvedValue(mockSettings); const settings = await client.settings(); expect(settings.hostname).toEqual("localhost.localdomain"); }); diff --git a/web/src/client/network/index.js b/web/src/client/network/index.js index 7cdc257aeb..3eb5e52ffe 100644 --- a/web/src/client/network/index.js +++ b/web/src/client/network/index.js @@ -106,8 +106,13 @@ class NetworkClient { * @return {Promise} */ async connections() { - const connections = await this.client.get("/network/connections"); + const response = await this.client.get("/network/connections"); + if (!response.ok) { + console.error("Failed to get list of connections", response); + return []; + } + const connections = await response.json(); return connections.map(this.fromApiConnection); } @@ -141,9 +146,14 @@ class NetworkClient { * @return {Promise} */ async accessPoints() { - const access_points = await this.client.get("/network/wifi"); - - return access_points.map(ap => { + const response = await this.client.get("/network/wifi"); + if (!response.ok) { + console.error("Failed to get list of APs", response); + return []; + } + const access_points = await response.json(); + + return access_points.map((ap) => { return createAccessPoint({ ssid: ap.ssid, hwAddress: ap.hw_address, @@ -169,7 +179,7 @@ class NetworkClient { * Apply network changes */ async apply() { - return this.client.put("/network/system/apply"); + return this.client.put("/network/system/apply", {}); } /** @@ -205,7 +215,13 @@ class NetworkClient { * @return {Promise} the added connection */ async addConnection(connection) { - return this.client.post("/network/connections", this.toApiConnection(connection)); + const response = await this.client.post("/network/connections", this.toApiConnection(connection)); + if (!response.ok) { + console.error("Failed to post list of connections", response); + return null; + } + + return response.json(); } /** @@ -232,7 +248,7 @@ class NetworkClient { async updateConnection(connection) { const conn = this.toApiConnection(connection); await this.client.put(`/network/connections/${conn.id}`, conn); - return this.apply(); + return (await this.apply()).ok; } /** @@ -246,7 +262,7 @@ class NetworkClient { */ async deleteConnection(id) { await this.client.delete(`/network/connections/${id}`); - return this.apply(); + return (await this.apply()).ok; } /* @@ -266,8 +282,13 @@ class NetworkClient { * * @return {Promise} */ - settings() { - return this.client.get("/network/state"); + async settings() { + const response = await this.client.get("/network/settings"); + if (!response.ok) { + console.error("Failed to get settings", response); + return {}; + } + return response.json(); } } diff --git a/web/src/client/software.test.js b/web/src/client/software.test.js index 5aeeaf6339..c714ef4590 100644 --- a/web/src/client/software.test.js +++ b/web/src/client/software.test.js @@ -25,6 +25,15 @@ import DBusClient from "./dbus"; import { HTTPClient } from "./http"; import { ProductClient, SoftwareClient } from "./software"; +const mockJsonFn = jest.fn(); + +const mockGetFn = jest.fn().mockImplementation(() => { + return { + ok: true, + json: mockJsonFn, + }; +}); + jest.mock("./http", () => { return { HTTPClient: jest.fn().mockImplementation(() => { @@ -35,8 +44,6 @@ jest.mock("./http", () => { }; }); -const mockGetFn = jest.fn(); - jest.mock("./dbus"); const PRODUCT_IFACE = "org.opensuse.Agama.Software1.Product"; @@ -82,7 +89,7 @@ describe("ProductClient", () => { it.only("returns the list of available products", async () => { const http = new HTTPClient(new URL("http://localhost")); const client = new ProductClient(http); - mockGetFn.mockResolvedValue([tumbleweed, microos]); + mockJsonFn.mockResolvedValue([tumbleweed, microos]); const products = await client.getAll(); expect(products).toEqual([ { id: "Tumbleweed", name: "openSUSE Tumbleweed", description: "Tumbleweed is..." }, @@ -95,7 +102,7 @@ describe("ProductClient", () => { it.only("returns the selected product", async () => { const http = new HTTPClient(new URL("http://localhost")); const client = new ProductClient(http); - mockGetFn.mockResolvedValue({ product: "microos" }); + mockJsonFn.mockResolvedValue({ product: "microos" }); const selected = await client.getSelected(); expect(selected).toEqual("microos"); });