Skip to content

Commit

Permalink
Fix Codacy Code Style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
argon committed Sep 25, 2016
1 parent 23a3b57 commit fd922fb
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 37 deletions.
2 changes: 1 addition & 1 deletion examples/sending-multiple-notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Send individualised notifications
i.e. Account updates for users with one-or-more device tokens
*/

const apn = require('apn');
const apn = require("apn");

let users = [
{ name: "Wendy", "devices": ["<insert device token>", "<insert device token>"]},
Expand Down
2 changes: 1 addition & 1 deletion examples/sending-to-multiple-devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ Possible use cases:
- Sport results
*/

const apn = require('apn');
const apn = require("apn");

let tokens = ["<insert token here>", "<insert token here>"];

Expand Down
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ module.exports = function (dependencies) {
}, notification.headers);

if (this.config.token) {
headers["authorization"] = "bearer " + this.config.token.current;
headers.authorization = "bearer " + this.config.token.current;
tokenGeneration = this.config.token.generation;
}

Expand Down Expand Up @@ -117,7 +117,7 @@ module.exports = function (dependencies) {
resolve(stream);
}
});
}
};

Client.prototype.shutdown = function shutdown() {
if (this.queue.length > 0) {
Expand Down
27 changes: 15 additions & 12 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,28 @@ module.exports = function(dependencies) {
}

if (options.token) {
const token = options.token;
if (!token.keyId) {
throw new Error("token.keyId is missing");
} else if(typeof token.keyId !== "string") {
throw new Error("token.keyId must be a string");
}

if (!token.teamId) {
throw new Error("token.teamId is missing");
} else if(typeof token.teamId !== "string") {
throw new Error("token.teamId must be a string");
}
validateToken(options.token);
}
}
}

return config;
};

function validateToken(token) {
if (!token.keyId) {
throw new Error("token.keyId is missing");
} else if(typeof token.keyId !== "string") {
throw new Error("token.keyId must be a string");
}

if (!token.teamId) {
throw new Error("token.teamId is missing");
} else if(typeof token.teamId !== "string") {
throw new Error("token.teamId must be a string");
}
}

function configureAddress(options) {
if (!options.address) {
if (options.production) {
Expand Down
2 changes: 1 addition & 1 deletion lib/credentials/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports = function (dependencies) {

const prepareCA = require("./ca/prepare")({
resolve,
})
});

return {
certificate: prepareCertificate,
Expand Down
2 changes: 1 addition & 1 deletion lib/credentials/token/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (dependencies) {
this.current = token();
}
}
}
};
} catch (err) {
throw new VError(err, "Failed to generate token");
}
Expand Down
8 changes: 5 additions & 3 deletions lib/protocol/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,13 @@ module.exports = function(dependencies) {

Endpoint.prototype._protocolError = function protocolError(component, errCode) {
this._error(component + " error: " + errCode);
}
};

Endpoint.prototype._error = function error(err) {
this.lastError = err;

this.emit("error", err);
}
};

Endpoint.prototype._goaway = function goaway(frame) {
// When we receive a goaway we must be prepared to
Expand All @@ -123,7 +123,9 @@ module.exports = function(dependencies) {
this._connection._streamIds.forEach( (stream, id) => {

// Ignore stream 0 (connection stream)
if (id === 0) return;
if (id === 0) {
return;
}

// let stream = this._connection._streamIds[id];

Expand Down
2 changes: 1 addition & 1 deletion lib/protocol/endpointManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ module.exports = function(dependencies) {
}

return this._connectionFailures >= this._config.connectionRetryLimit;
}
};

EndpointManager.prototype.createEndpoint = function createEndpoint() {
if (this._currentConnection || this._endpoints.length >= this._config.maxConnections) {
Expand Down
2 changes: 1 addition & 1 deletion lib/provider.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ module.exports = function(dependencies) {

Provider.prototype.shutdown = function shutdown() {
this.client.shutdown();
}
};

return Provider;
};
6 changes: 3 additions & 3 deletions test/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ describe("Client", function () {
generation: 0,
current: "fake-token",
regenerate: sinon.stub(),
}
};

client = new Client( { address: "testapi", token: fakes.token } );

Expand All @@ -137,7 +137,7 @@ describe("Client", function () {
expect(fakes.stream.headers).to.be.calledWithMatch({
authorization: "bearer fake-token",
});
})
});
});
});

Expand Down Expand Up @@ -535,7 +535,7 @@ describe("Client", function () {

fakes.token.regenerate = function () {
fakes.token.generation = 1;
fakes.token.current = "second-token"
fakes.token.current = "second-token";
}

fakes.endpointManager.getStream.onCall(0).returns(fakes.streams[0]);
Expand Down
2 changes: 1 addition & 1 deletion test/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe("config", function () {
it("throws an error if teamId is not a string", function () {
expect(() => config({ token: { key, keyId, teamId: 123 }})).to.throw(/token\.teamId must be a string/);
});
})
});

it("does not invoke prepareCertificate", function () {
let configuration = config({ token: { key, keyId, teamId } });
Expand Down
4 changes: 2 additions & 2 deletions test/credentials/token/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe("perpareToken", function () {

beforeEach(function() {
fakes.resolve.withArgs("key.pem").returns("keyData");
fakes.sign.returns("generated-token")
fakes.sign.returns("generated-token");

token = prepareToken(testOptions);
});
Expand Down Expand Up @@ -105,7 +105,7 @@ describe("perpareToken", function () {

it("does not change the `current` property", function () {
expect(token.current).to.equal("generated-token");
})
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/notification/apsProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ describe("Notification", function() {

it("sets the aps.alert.action property", function () {
expect(compiledOutput()).to.have.deep.property("aps.alert.action", "Investigate");
})
});
});

describe("setAction", function () {
Expand Down
10 changes: 5 additions & 5 deletions test/protocol/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ describe("Endpoint", function () {

beforeEach(function () {
let endpoint = new Endpoint({});
endpoint.on("error", () => {})
endpoint.on("error", () => {});

streams.connection._streamIds = [];

Expand Down Expand Up @@ -547,13 +547,13 @@ describe("Endpoint", function () {
});

context("with error", function () {
const debug_data = new Buffer(6);
debug_data.write("error!");
const debugData = new Buffer(6);
debugData.write("error!");

const formattedError = "GOAWAY: PROTOCOL_ERROR error!";

beforeEach(function () {
frame = { error: "PROTOCOL_ERROR", debug_data: debug_data };
frame = { error: "PROTOCOL_ERROR", debug_data: debugData };
});

it("emits an error with the type and debug data", function () {
Expand Down Expand Up @@ -620,7 +620,7 @@ describe("Endpoint", function () {
expect(errorSpy).to.be.calledTwice.and.calledWith(formattedError);
});
});
})
});
});

describe("`wakeup` event", function () {
Expand Down
4 changes: 2 additions & 2 deletions test/protocol/endpointManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ describe("Endpoint Manager", function () {

beforeEach(function () {
establishedEndpoint = establishEndpoint(manager);
})
});

context("when the configured number of connections fail", function () {
it("does not emit an error", function() {
Expand Down Expand Up @@ -501,7 +501,7 @@ describe("Endpoint Manager", function () {
manager.getStream();

if(fakes.Endpoint.callCount !== callCount + 1) {
return null
return null;
}

let endpoint = fakes.Endpoint.lastCall.returnValue;
Expand Down

0 comments on commit fd922fb

Please sign in to comment.