Skip to content
This repository has been archived by the owner on Nov 30, 2020. It is now read-only.

Commit

Permalink
Add tests for the installer module
Browse files Browse the repository at this point in the history
"Please do not attempt to remove testing apparatus from the testing area." -GLaDOS
  • Loading branch information
NeoTheThird committed Mar 7, 2018
1 parent f79882e commit ca5a7f0
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions tests/unit-tests/test_installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ chai.use(sinonChai);

const Installer = require('../../src/module.js').Installer;

const devicesJson = require("../test-data/devices.json")
const deviceBaconJson = require("../test-data/device-bacon.json")
const deviceFP2Json = require("../test-data/device-FP2.json")

describe('Installer module', function() {
describe("constructor()", function() {
it("should create default installer-api-client", function() {
Expand Down Expand Up @@ -68,4 +72,100 @@ describe('Installer module', function() {
}
});
});

describe("getDevices()", function() {
it("should return devices", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(false, {statusCode: 200}, devicesJson);
});

const api = new Installer();
return api.getDevices().then((result) => {
expect(result).to.eql(devicesJson);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/devices",
json: true
});
});
});

it("should return error", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(true, {statusCode: 500}, devicesJson);
});

const api = new Installer();
return api.getDevices().then(() => {}).catch((err) => {
expect(err).to.eql(true);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/devices",
json: true
});
});
});
});

describe("getDevice()", function() {
it("should return devices", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(false, {statusCode: 200}, deviceBaconJson);
});

const api = new Installer();
return api.getDevice("bacon").then((result) => {
expect(result).to.eql(deviceBaconJson);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/devices/bacon",
json: true
});
});
});

it("should return error", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(true, {statusCode: 500}, deviceBaconJson);
});

const api = new Installer();
return api.getDevice("bacon").then(() => {}).catch((err) => {
expect(err).to.eql(true);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/devices/bacon",
json: true
});
});
});
});

describe("getInstallInstructs()", function() {
it("should return devices", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(false, {statusCode: 200}, deviceBaconJson);
});

const api = new Installer();
return api.getInstallInstructs("bacon").then((result) => {
expect(result).to.eql(deviceBaconJson);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/bacon",
json: true
});
});
});

it("should return error", function() {
const requestStub = this.sandbox.stub(request, 'get').callsFake(function(url, cb) {
cb(true, {statusCode: 500}, deviceBaconJson);
});

const api = new Installer();
return api.getInstallInstructs("bacon").then(() => {}).catch((err) => {
expect(err).to.eql(true);
expect(requestStub).to.have.been.calledWith({
url: "https://devices.ubports.com/api/installer/bacon",
json: true
});
});
});
});
});

0 comments on commit ca5a7f0

Please sign in to comment.