-
Notifications
You must be signed in to change notification settings - Fork 120
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test asteroid_os and systemimage APIs
- Loading branch information
1 parent
456a6e1
commit 921649e
Showing
4 changed files
with
178 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,58 @@ | ||
process.argv = [null, null, "-vv"]; | ||
const { ipcMain } = require("electron"); | ||
jest.mock("electron"); | ||
|
||
const axios = require("axios"); | ||
jest.mock("axios"); | ||
axios.create.mockReturnValue(axios); | ||
const api = require("./api.js"); | ||
|
||
it("should construct", () => expect(require("./api.js")).toBeDefined()); | ||
describe("asteroid_os api", () => { | ||
describe("getImages", () => { | ||
it("should resolve images", () => { | ||
axios.get.mockResolvedValueOnce({ data: "123 a\n456 b\n" }); | ||
return api.getImages("1.0", "lenok").then(r => | ||
expect(r).toEqual([ | ||
{ | ||
checksum: { algorithm: "md5", sum: "123" }, | ||
url: "https://release.asteroidos.org/1.0/lenok/a" | ||
}, | ||
{ | ||
checksum: { algorithm: "md5", sum: "456" }, | ||
url: "https://release.asteroidos.org/1.0/lenok/b" | ||
} | ||
]) | ||
); | ||
}); | ||
it("should reject on 404", done => { | ||
axios.get.mockRejectedValueOnce({ response: { status: 404 } }); | ||
return api.getImages("1.0", "lenok").catch(e => { | ||
expect(e.message).toEqual("404"); | ||
done(); | ||
}); | ||
}); | ||
it("should reject on network error", done => { | ||
axios.get.mockRejectedValueOnce({ response: {} }); | ||
return api.getImages("1.0", "lenok").catch(e => { | ||
expect(e.message).toEqual("no network"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe("getChannels", () => { | ||
it("should resolve channels", () => { | ||
axios.get.mockResolvedValue({ data: "123 a\n456 b\n" }); | ||
axios.get.mockRejectedValueOnce({ response: { status: 404 } }); | ||
return api | ||
.getChannels("lenok") | ||
.then(r => expect(r).toEqual(["nightlies", "1.0-alpha"])); | ||
}); | ||
it("should reject on error", done => { | ||
axios.get.mockResolvedValue({ data: "123 a\n456 b\n" }); | ||
axios.get.mockRejectedValueOnce({ response: {} }); | ||
return api.getChannels("lenok").catch(r => { | ||
expect(r.message).toEqual("no network"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,128 @@ | ||
process.argv = [null, null, "-vv"]; | ||
const { ipcMain } = require("electron"); | ||
jest.mock("electron"); | ||
|
||
const axios = require("axios"); | ||
jest.mock("axios"); | ||
axios.create.mockReturnValue(axios); | ||
const api = require("./api.js"); | ||
|
||
it("should construct", () => expect(require("./api.js")).toBeDefined()); | ||
const files = [ | ||
{ | ||
checksum: { algorithm: "sha256", sum: "1337" }, | ||
url: "https://system-image.ubports.com/asdf.img" | ||
}, | ||
{ url: "https://system-image.ubports.com/asdf.img.asc" }, | ||
{ | ||
url: "https://system-image.ubports.com/gpg/image-signing.tar.xz" | ||
}, | ||
{ | ||
url: "https://system-image.ubports.com/gpg/image-signing.tar.xz.asc" | ||
}, | ||
{ | ||
url: "https://system-image.ubports.com/gpg/image-master.tar.xz" | ||
}, | ||
{ | ||
url: "https://system-image.ubports.com/gpg/image-master.tar.xz.asc" | ||
} | ||
]; | ||
|
||
describe("systemimage api", () => { | ||
describe("getImages", () => { | ||
it("should resolve images", () => { | ||
axios.get.mockResolvedValueOnce({ | ||
data: { | ||
images: [ | ||
{ | ||
type: "full", | ||
files: [ | ||
{ | ||
checksum: "1337", | ||
path: "asdf.img", | ||
signature: "asdf.img.asc" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}); | ||
return api.getImages("16.04/stable", "bacon").then(r => | ||
expect(r).toEqual({ | ||
commands: | ||
"format system\n\ | ||
load_keyring image-master.tar.xz image-master.tar.xz.asc\n\ | ||
load_keyring image-signing.tar.xz image-signing.tar.xz.asc\n\ | ||
mount system\n\n\ | ||
update asdf.img asdf.img.asc\n\ | ||
unmount system", | ||
files | ||
}) | ||
); | ||
}); | ||
describe("getImages", () => { | ||
it("should resolve images", () => { | ||
axios.get.mockResolvedValueOnce({ | ||
data: { | ||
images: [ | ||
{ | ||
type: "full", | ||
files: [ | ||
{ | ||
checksum: "1337", | ||
path: "asdf.img", | ||
signature: "asdf.img.asc" | ||
} | ||
] | ||
} | ||
] | ||
} | ||
}); | ||
return api | ||
.getImages("16.04/stable", "bacon", true, ["developer_mode"], ["mtp"]) | ||
.then(r => | ||
expect(r).toEqual({ | ||
commands: | ||
"format system\n\ | ||
load_keyring image-master.tar.xz image-master.tar.xz.asc\n\ | ||
load_keyring image-signing.tar.xz image-signing.tar.xz.asc\n\ | ||
mount system\n\ | ||
format data\n\ | ||
update asdf.img asdf.img.asc\n\ | ||
enable developer_mode\n\ | ||
disable mtp\n\ | ||
unmount system", | ||
files | ||
}) | ||
); | ||
}); | ||
it("should reject on 404", done => { | ||
axios.get.mockRejectedValueOnce({ response: { status: 404 } }); | ||
return api.getImages("1.0", "lenok").catch(e => { | ||
expect(e.message).toEqual("404"); | ||
done(); | ||
}); | ||
}); | ||
it("should reject on network error", done => { | ||
axios.get.mockRejectedValueOnce({ response: {} }); | ||
return api.getImages("1.0", "lenok").catch(e => { | ||
expect(e.message).toEqual("no network"); | ||
done(); | ||
}); | ||
}); | ||
}); | ||
describe("getChannels", () => { | ||
it("should resolve channels", () => { | ||
axios.get.mockResolvedValue({ | ||
data: { | ||
"16.04/stable": { devices: { bacon: "a" } }, | ||
"17.04/stable": { devices: { bacon: "a" }, hidden: true }, | ||
"18.04/stable": { devices: { bacon: "a" }, redirect: "asdf" }, | ||
"19.04/stable": { devices: { hamburger: "a" } } | ||
} | ||
}); | ||
return api | ||
.getChannels("bacon") | ||
.then(r => expect(r).toEqual(["16.04/stable"])); | ||
}); | ||
}); | ||
}); | ||
}); |