Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "siguex", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Make the communication with sigue much easier", | ||
@@ -5,0 +5,0 @@ "main": "siguex.js", |
const login = require('./src/login') | ||
module.exports = Object.freeze({ login }) | ||
class Siguex { | ||
constructor (token, { setToken, clearToken }) { | ||
this.token = token | ||
this.setTokenCallback = setToken | ||
this.clearTokenCallback = clearToken | ||
} | ||
setToken (token) { | ||
this.token = token | ||
this.setTokenCallback(token) | ||
} | ||
clearToken () { | ||
delete this.token | ||
this.clearTokenCallback() | ||
} | ||
} | ||
[login].forEach((method) => { | ||
Siguex.prototype[method.name] = function () { | ||
return method.apply(this, Array.from(arguments).concat(this.token)) | ||
} | ||
}) | ||
module.exports = Siguex |
@@ -32,3 +32,3 @@ const dependencies = { | ||
module.exports = function login (username, password, injection) { | ||
module.exports = function login (username, password, token, injection) { | ||
const { | ||
@@ -35,0 +35,0 @@ http, |
@@ -36,3 +36,3 @@ const { expect } = require('chai') | ||
prepareMocks(nonSuccessResponse) | ||
return login(username, password, dependencies).then(result => { | ||
return login(username, password, null, dependencies).then(result => { | ||
expect(result.success).to.equal(false) | ||
@@ -45,3 +45,3 @@ expect(result.token).to.equal(undefined) | ||
prepareMocks(successResponse) | ||
return login(username, password, dependencies).then(result => { | ||
return login(username, password, null, dependencies).then(result => { | ||
expect(result.success).to.equal(true) | ||
@@ -48,0 +48,0 @@ expect(result.token).to.equal(token) |
73408
106