Skip to content

Commit

Permalink
Named ApiRequest.sign() parameters. Fixed ApiRequest test labels.
Browse files Browse the repository at this point in the history
  • Loading branch information
rattletone committed Aug 2, 2019
1 parent 849530c commit 7c57c67
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
7 changes: 4 additions & 3 deletions lib/ApiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ class ApiRequest {
* @param {Function} [callback] - Callback of API request
*/

send(...args) {
const method = typeof args[0] === "string" ? args[0] : undefined;
const callback = args.length > 1 ? typeof args[1] === "function" ? args[1] : undefined : typeof args[0] === "function" ? args[0] : undefined;
send(method, callback) {
callback = callback === undefined ? typeof method === "function" ? method : undefined : typeof callback === "function" ? callback : undefined;
method = typeof method === "string" ? method : undefined;

const params = Object.fromEntries(Object
.entries(this)
.filter(([key]) => key !== "callback")
Expand Down
20 changes: 10 additions & 10 deletions lib/LastFm.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ class LastFm {
throw new TypeError("apiKey must be of type string");
}

if(secret !== undefined && typeof secret !== "string") {
throw new TypeError("secret must be of type string");
}

if(sessionKey !== undefined && typeof sessionKey !== "string") {
throw new TypeError("sessionKey must be of type string");
}

this.apiKey = apiKey;

if(secret) {
if(secret !== undefined) {
if(typeof secret !== "string") {
throw new TypeError("secret must be of type string");
}

this.secret = secret;
}

if(sessionKey) {
if(sessionKey !== undefined) {
if(typeof sessionKey !== "string") {
throw new TypeError("sessionKey must be of type string");
}

this.sessionKey = sessionKey;
}
}
Expand Down
14 changes: 7 additions & 7 deletions test/ApiRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ describe("ApiRequest()", () => {
});
});

test("invoke callback if funtion is passed as the only argument", done => {
test("invoke callback if function is passed as the first argument and no second argument is passed", done => {
const apiRequest = new ApiRequest();

nock("http://ws.audioscrobbler.com")
Expand All @@ -121,7 +121,7 @@ describe("ApiRequest()", () => {
});
});

test("invoke callback if funtion is passed as the second argument", done => {
test("invoke callback if function is passed as the second argument", done => {
const apiRequest = new ApiRequest();

nock("http://ws.audioscrobbler.com")
Expand All @@ -136,7 +136,7 @@ describe("ApiRequest()", () => {
});
});

test("return promise if function is not passed as the only argument", () => {
test("return promise if function is not passed as the first argument and no second argument is passed", () => {
const apiRequest = new ApiRequest();

nock("http://ws.audioscrobbler.com")
Expand Down Expand Up @@ -215,10 +215,10 @@ describe("ApiRequest()", () => {
.replyWithError({});

apiRequest.send((err, data) => {
expect(err).toBeDefined();
expect(data).toBeNull();
done();
});
expect(err).toBeDefined();
expect(data).toBeNull();
done();
});
});
});
});

0 comments on commit 7c57c67

Please sign in to comment.