forked from kaiwood/pnut-butter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Kai Wood
committed
Apr 17, 2017
1 parent
ee9d138
commit 2190ef1
Showing
4 changed files
with
79 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,47 @@ | ||
const chai = require('chai'); | ||
const chaiAsPromised = require('chai-as-promised'); | ||
const nock = require('nock'); | ||
const chai = require("chai"); | ||
const chaiAsPromised = require("chai-as-promised"); | ||
const nock = require("nock"); | ||
chai.use(chaiAsPromised); | ||
chai.should(); | ||
const expect = chai.expect; | ||
|
||
const pnut = require('../lib/pnut'); | ||
const pnut = require("../lib/pnut"); | ||
|
||
before(function () { | ||
let base = 'https://api.pnut.io/v0'; | ||
before(function() { | ||
let base = "https://api.pnut.io/v0"; | ||
|
||
nock(base) | ||
.get('/somewhere') | ||
.reply(200, {}); | ||
nock(base).get("/somewhere").reply(200, {}); | ||
|
||
nock(base) | ||
.post('/somewhere') | ||
.reply(200, {}); | ||
nock(base).post("/somewhere").reply(200, {}); | ||
|
||
nock(base) | ||
.put('/somewhere') | ||
.reply(200, {}); | ||
nock(base).put("/somewhere").reply(200, {}); | ||
|
||
nock(base) | ||
.patch('/somewhere') | ||
.reply(200, {}); | ||
nock(base).patch("/somewhere").reply(200, {}); | ||
}); | ||
|
||
after(function () { | ||
after(function() { | ||
nock.cleanAll(); | ||
}); | ||
|
||
describe('The pnut-butter library', () => { | ||
it('should be able to send a custom GET request', () => { | ||
return pnut.custom('/somewhere').should.become({}); | ||
describe("The pnut-butter library", () => { | ||
it("should be able to send a custom GET request", () => { | ||
return pnut.custom("/somewhere").should.become({}); | ||
}); | ||
|
||
it('should be able to send a custom POST request', () => { | ||
return pnut.custom('/somewhere', 'POST', { | ||
text: 'sometext' | ||
it("should be able to send a custom POST request", () => { | ||
return pnut.custom("/somewhere", "POST", { | ||
text: "sometext" | ||
}); | ||
}); | ||
|
||
it('should be able to send a custom PUT request', () => { | ||
return pnut.custom('/somewhere', 'PUT', { | ||
text: 'sometext' | ||
it("should be able to send a custom PUT request", () => { | ||
return pnut.custom("/somewhere", "PUT", { | ||
text: "sometext" | ||
}); | ||
}); | ||
|
||
it('should be able to send a custom PATCH request', () => { | ||
return pnut.custom('/somewhere', 'PATCH', { | ||
text: 'sometext' | ||
it("should be able to send a custom PATCH request", () => { | ||
return pnut.custom("/somewhere", "PATCH", { | ||
text: "sometext" | ||
}); | ||
}); | ||
}); | ||
|
||
describe('Authentication', () => { | ||
it('should fail when no client id is given', () => { | ||
expect(() => pnut.authenticateClientURL('', 'http://github.com')).to.throw(Error); | ||
}); | ||
|
||
it('should fail if no redirect uri is given', () => { | ||
expect(() => pnut.authenticateClientURL('sometoken', '')).to.throw(Error); | ||
}); | ||
|
||
it('should give back a correct url where the client can authenticate', () => { | ||
let expectedURL = 'https://pnut.io/oauth/authenticate?client_id=mytoken&redirect_uri=http://github.com&scope=basic,stream,write_post,follow,update_profile,presence,messages,public_messages&response_type=token'; | ||
|
||
expect(pnut.authenticateClientURL('mytoken', 'http://github.com')).to.equal(expectedURL); | ||
}); | ||
}); |