Skip to content

Commit 1079482

Browse files
committed
test: lint tests
1 parent 9173383 commit 1079482

9 files changed

Lines changed: 37 additions & 45 deletions

.eslintignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
11
node_modules/
22
dist/
33
coverage/
4-
test/
5-

.eslintrc

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22
"env": {
33
"browser": true,
44
"es6": true,
5-
"node": true
6-
},
7-
"globals": {
8-
"CTX": true,
9-
"console": true
5+
"node": true,
6+
"mocha": true
107
},
118
"extends": "eslint:recommended",
129
"rules": {
@@ -29,10 +26,6 @@
2926
"error",
3027
"always"
3128
],
32-
"one-var": [
33-
"error",
34-
"always"
35-
],
3629
"eol-last": [
3730
"error",
3831
"always"
@@ -51,8 +44,7 @@
5144
{
5245
"max": 2
5346
}
54-
],
55-
"no-console":0
47+
]
5648
},
5749
"parserOptions": {
5850
"sourceType": "module"

test/storage.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// Mock in-memory user storage
22
export default function UserStorage() {
33
this.storage = {};
4-
};
4+
}
55

66
UserStorage.prototype.setItem = function (key, value) {
7-
this.storage[key] = value || '';
7+
this.storage[key] = value || "";
88
};
99

1010
UserStorage.prototype.getItem = function (key) {
@@ -15,6 +15,6 @@ UserStorage.prototype.removeItem = function (key) {
1515
delete this.storage[key];
1616
};
1717

18-
UserStorage.prototype.clear = function (key) {
18+
UserStorage.prototype.clear = function () {
1919
this.storage = {};
2020
};

test/test-authentication.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe("Client _finishAuthentication", function () {
153153

154154
it("should return error when _renewSecret fails", function(done) {
155155
sinon.stub(client.http, "request").yields(null, { success: true, dvsRegister: { test: 1 } });
156-
var renewSecretStub = sinon.stub(client, "_renewSecret").yields(new Error("Renew secret error"));
156+
sinon.stub(client, "_renewSecret").yields(new Error("Renew secret error"));
157157

158158
client._finishAuthentication("test@example.com", 1234, ["dvs-auth"], "authOTT", function (err) {
159159
expect(err).to.exist;
@@ -240,7 +240,7 @@ describe("Client _renewSecret", function () {
240240
client._createMPinID.restore && client._createMPinID.restore();
241241
client._getSecret.restore && client._getSecret.restore();
242242
client._createIdentity.restore && client._createIdentity.restore();
243-
})
243+
});
244244
});
245245

246246
describe("Client _authentication", function () {
@@ -275,7 +275,7 @@ describe("Client _authentication", function () {
275275
var getPass2Stub = sinon.stub(client, "_getPass2").yields(null, {});
276276
var finishAuthenticationStub = sinon.stub(client, "_finishAuthentication").yields(null, { success: true });
277277

278-
client._authentication("test@example.com", "1234", ['oidc'], function (err, data) {
278+
client._authentication("test@example.com", "1234", ["oidc"], function (err, data) {
279279
expect(err).to.be.null;
280280
expect(data).to.deep.equal({ success: true });
281281
expect(getPass1Stub.calledOnce).to.be.true;
@@ -288,7 +288,7 @@ describe("Client _authentication", function () {
288288
it("should call callback with error when _getPass1 fails", function (done) {
289289
sinon.stub(client, "_getPass1").yields(new Error("Request error"), null);
290290

291-
client._authentication("test@example.com", "1234", ['oidc'], function (err, data) {
291+
client._authentication("test@example.com", "1234", ["oidc"], function (err, data) {
292292
expect(err).to.exist;
293293
expect(data).to.be.null;
294294
done();
@@ -298,7 +298,7 @@ describe("Client _authentication", function () {
298298
it("should call callback with error when MPIN ID has expired", function (done) {
299299
sinon.stub(client, "_getPass1").yields(new Error("Request error"), { error: "EXPIRED_MPINID" });
300300

301-
client._authentication("test@example.com", "1234", ['oidc'], function (err, data) {
301+
client._authentication("test@example.com", "1234", ["oidc"], function (err, data) {
302302
expect(err).to.exist;
303303
expect(err.message).to.equal("Revoked");
304304
expect(data).to.be.null;
@@ -309,7 +309,7 @@ describe("Client _authentication", function () {
309309
it("should call callback with error when _getPass1 fails", function (done) {
310310
sinon.stub(client, "_getPass1").yields(new Error("Request error"), null);
311311

312-
client._authentication("test@example.com", "1234", ['oidc'], function (err, data) {
312+
client._authentication("test@example.com", "1234", ["oidc"], function (err, data) {
313313
expect(err).to.exist;
314314
expect(data).to.be.null;
315315
done();
@@ -320,7 +320,7 @@ describe("Client _authentication", function () {
320320
sinon.stub(client, "_getPass1").yields(null, { success: true });
321321
sinon.stub(client, "_getPass2").yields(new Error("Request error"), null);
322322

323-
client._authentication("test@example.com", "1234", ['oidc'], function (err, data) {
323+
client._authentication("test@example.com", "1234", ["oidc"], function (err, data) {
324324
expect(err).to.exist;
325325
expect(data).to.be.null;
326326
done();
@@ -549,7 +549,7 @@ describe("Client generateQuickCode", function () {
549549

550550
it("should call _authentication with scope 'reg-code'", function (done) {
551551
var authenticationStub = sinon.stub(client, "_authentication").yields(null, {});
552-
var requestStub = sinon.stub(client.http, "request").yields(null, { code: "123456", ttlSeconds: 60, expireTime: 1737520575 });
552+
sinon.stub(client.http, "request").yields(null, { code: "123456", ttlSeconds: 60, expireTime: 1737520575 });
553553

554554
client.generateQuickCode("test@example.com", "1234", function (err, data) {
555555
expect(err).to.be.null;
@@ -564,7 +564,7 @@ describe("Client generateQuickCode", function () {
564564
});
565565

566566
it("should fail on _authentication error", function (done) {
567-
var authenticationStub = sinon.stub(client, "_authentication").yields(new Error("Authentication fail"), null);
567+
sinon.stub(client, "_authentication").yields(new Error("Authentication fail"), null);
568568

569569
client.generateQuickCode("test@example.com", "1234", function (err, data) {
570570
expect(err).to.exist;
@@ -575,8 +575,8 @@ describe("Client generateQuickCode", function () {
575575
});
576576

577577
it("should fail on verification/quickcode request error", function (done) {
578-
var authenticationStub = sinon.stub(client, "_authentication").yields(null, {});
579-
var requestStub = sinon.stub(client.http, "request").yields(new Error("Request error"), null);
578+
sinon.stub(client, "_authentication").yields(null, {});
579+
sinon.stub(client.http, "request").yields(new Error("Request error"), null);
580580

581581
client.generateQuickCode("test@example.com", "1234", function (err, data) {
582582
expect(err).to.exist;

test/test-client.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Client from "../src/client.js";
2-
import pkg from "../package.json" with { type: "json" };
2+
import { readFileSync } from "fs";
33
import sinon from "sinon";
44
import { expect } from "chai";
55
import testConfig from "./config.js";
66

7+
const pkg = JSON.parse(readFileSync("./package.json"));
8+
79
describe("Client", function() {
810
it("should throw Error w/o options", function () {
911
expect(function () {
@@ -137,7 +139,7 @@ describe("Client fetchAccessId", function () {
137139
});
138140

139141
it("should set the access ID", function () {
140-
var requestStub = sinon.stub(client.http, "request").yields(null, sessionInfo);
142+
sinon.stub(client.http, "request").yields(null, sessionInfo);
141143

142144
client.fetchAccessId("test@example.com", function (err, data) {
143145
expect(err).to.be.null;
@@ -159,15 +161,15 @@ describe("Client fetchStatus", function() {
159161
});
160162

161163
it("should make a request for session status", function () {
162-
var requestStub = sinon.stub(client.http, "request").yields(null, { status: "new" });
164+
sinon.stub(client.http, "request").yields(null, { status: "new" });
163165

164166
client.fetchStatus(function (err, data) {
165167
expect(data.status).to.equal("new");
166168
});
167169
});
168170

169171
it("should fail when request fails", function () {
170-
var requestStub = sinon.stub(client.http, "request").yields(new Error("Error"), null);
172+
sinon.stub(client.http, "request").yields(new Error("Error"), null);
171173

172174
client.fetchStatus(function (err, data) {
173175
expect(err).to.exist;
@@ -202,7 +204,7 @@ describe("Client sendPushNotificationForAuth", function () {
202204
});
203205

204206
it("should fail when the request fails", function () {
205-
var requestStub = sinon.stub(client.http, "request").yields(new Error("Request error"), { status: 400 });
207+
sinon.stub(client.http, "request").yields(new Error("Request error"), { status: 400 });
206208

207209
client.sendPushNotificationForAuth("test@example.com", function (err, data) {
208210
expect(err).to.exist;
@@ -211,7 +213,7 @@ describe("Client sendPushNotificationForAuth", function () {
211213
});
212214

213215
it("should fail when the request fails", function () {
214-
var requestStub = sinon.stub(client.http, "request").yields(new Error("Request error"), { status: 400, error: "NO_PUSH_TOKEN" });
216+
sinon.stub(client.http, "request").yields(new Error("Request error"), { status: 400, error: "NO_PUSH_TOKEN" });
215217

216218
client.sendPushNotificationForAuth("test@example.com", function (err, data) {
217219
expect(err).to.exist;

test/test-crypto.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe("Crypto extractPin", function () {
7272
it("should throw error on crypto failure", function () {
7373
sinon.stub(crypto._crypto().MPIN, "EXTRACT_PIN").returns(-1);
7474
expect(function () {
75-
crypto.extractPin("0f", "0f", "1234", "hex", "BN254CX")
75+
crypto.extractPin("0f", "0f", "1234", "hex", "BN254CX");
7676
}).to.throw("Could not extract PIN from client secret: -1");
7777
});
7878

test/test-http.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import sinon from "sinon";
33
import { expect } from "chai";
44

55
describe("HTTP request", function() {
6-
var client, server, requests;
6+
var client, requests;
77

88
before(function () {
99
var xhr = global.XMLHttpRequest = sinon.useFakeXMLHttpRequest();

test/test-registration.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ describe("Client _getDeviceName", function () {
160160
config.deviceName = "test";
161161
client = new Client(config);
162162
expect(client._getDeviceName()).to.equal("test");
163-
})
163+
});
164164
});
165165

166166
describe("Client _getSecret", function() {
@@ -269,7 +269,7 @@ describe("Client _createIdentity", function() {
269269
expect(extractPinStub.firstCall.args[1]).to.equal("0f");
270270
expect(extractPinStub.firstCall.args[2]).to.equal("1234");
271271
done();
272-
}, function (err) {
272+
}, function () {
273273
throw new Error();
274274
});
275275
});
@@ -288,7 +288,7 @@ describe("Client _createIdentity", function() {
288288

289289
it("should call callback with error when extractPin fails", function(done) {
290290
var thrownError = new Error;
291-
var addSharesStub = sinon.stub(client.crypto, "addShares");
291+
sinon.stub(client.crypto, "addShares");
292292
var extractPinStub = sinon.stub(client.crypto, "extractPin").throws(thrownError);
293293

294294
client._createIdentity("test@example.com", "1234", {}, {}, {}, {}, function(err, data) {
@@ -428,9 +428,9 @@ describe("Client register", function () {
428428
});
429429

430430
it("should pass provided PIN length to the PIN callback", function (done) {
431-
var registrationStub = sinon.stub(client, "_createMPinID").yields(null, { pinLength: 5, projectId: "projectID", secretUrls: ["http://example.com/secret1", "http://example.com/secret2"] });
432-
var getSecretStub = sinon.stub(client, "_getSecret").yields(null);
433-
var createIdentityStub = sinon.stub(client, "_createIdentity").yields(null, { identity: true });
431+
sinon.stub(client, "_createMPinID").yields(null, { pinLength: 5, projectId: "projectID", secretUrls: ["http://example.com/secret1", "http://example.com/secret2"] });
432+
sinon.stub(client, "_getSecret").yields(null);
433+
sinon.stub(client, "_createIdentity").yields(null, { identity: true });
434434

435435
client.register("test@example.com", "activationToken", function (passPin, pinLength) {
436436
expect(pinLength).to.equal(5);
@@ -443,9 +443,9 @@ describe("Client register", function () {
443443
});
444444

445445
it("should pass default PIN length to the PIN callback", function (done) {
446-
var registrationStub = sinon.stub(client, "_createMPinID").yields(null, { projectId: "projectID", secretUrls: ["http://example.com/secret1", "http://example.com/secret2"] });
447-
var getSecretStub = sinon.stub(client, "_getSecret").yields(null);
448-
var createIdentityStub = sinon.stub(client, "_createIdentity").yields(null, { identity: true });
446+
sinon.stub(client, "_createMPinID").yields(null, { projectId: "projectID", secretUrls: ["http://example.com/secret1", "http://example.com/secret2"] });
447+
sinon.stub(client, "_getSecret").yields(null);
448+
sinon.stub(client, "_createIdentity").yields(null, { identity: true });
449449

450450
client.register("test@example.com", "activationToken", function (passPin, pinLength) {
451451
expect(pinLength).to.equal(4);

test/test-users.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ describe("Users remove", function () {
430430

431431
afterEach(function () {
432432
users.store.restore && users.store.restore();
433-
})
433+
});
434434
});
435435

436436
describe("Users get", function () {

0 commit comments

Comments
 (0)