-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(tests): fix failing unit test for request query #41
Open
bhavya3024
wants to merge
1
commit into
Medium:master
Choose a base branch
from
bhavya3024:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
{ | ||
"name": "medium-sdk" | ||
, "description": "NodeJS client for the Medium app" | ||
, "version": "0.0.4" | ||
, "homepage": "https://github.com/medium/medium-sdk-nodejs" | ||
, "author": "Jamie Talbot <[email protected]> (https://github.com/majelbstoat)" | ||
, "keywords": ["medium", "api", "writing"] | ||
, "main": "index.js" | ||
, "repository": { | ||
"type": "git" | ||
, "url": "https://github.com/medium/medium-sdk-nodejs.git" | ||
} | ||
, "devDependencies": { | ||
"mocha": "^2.2.5" | ||
, "should": "^7.1" | ||
, "nock": "^2.17" | ||
"name": "medium-sdk", | ||
"description": "NodeJS client for the Medium app", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/medium/medium-sdk-nodejs", | ||
"author": "Jamie Talbot <[email protected]> (https://github.com/majelbstoat)", | ||
"keywords": [ | ||
"medium", | ||
"api", | ||
"writing" | ||
], | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/medium/medium-sdk-nodejs.git" | ||
}, | ||
"devDependencies": { | ||
"mocha": "^2.2.5", | ||
"nock": "^2.17", | ||
"should": "^13.2.3" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
} | ||
} |
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 |
---|---|---|
|
@@ -18,17 +18,17 @@ describe('MediumClient - constructor', function () { | |
}) | ||
|
||
it('should throw a MediumError when only clientId is provided', function (done) { | ||
(function () { new medium.MediumClient({clientId: 'xxx'}) }).should.throw(medium.MediumError) | ||
(function () { new medium.MediumClient({ clientId: 'xxx' }) }).should.throw(medium.MediumError) | ||
done() | ||
}) | ||
|
||
it('should throw a MediumError when only clientSecret is provided', function (done) { | ||
(function () { new medium.MediumClient({clientSecret: 'yyy'}) }).should.throw(medium.MediumError) | ||
(function () { new medium.MediumClient({ clientSecret: 'yyy' }) }).should.throw(medium.MediumError) | ||
done() | ||
}) | ||
|
||
it('should succeed when both clientId and clientSecret are provided', function (done) { | ||
var client = new medium.MediumClient({clientId: 'xxx', clientSecret: 'yyy'}) | ||
var client = new medium.MediumClient({ clientId: 'xxx', clientSecret: 'yyy' }) | ||
done() | ||
}) | ||
}) | ||
|
@@ -41,7 +41,7 @@ describe('MediumClient - methods', function () { | |
var client | ||
|
||
beforeEach(function () { | ||
client = new medium.MediumClient({clientId: clientId, clientSecret: clientSecret}) | ||
client = new medium.MediumClient({ clientId: clientId, clientSecret: clientSecret }) | ||
nock.disableNetConnect() | ||
}) | ||
|
||
|
@@ -52,7 +52,7 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#setAccessToken', function () { | ||
|
||
it ('sets the access token', function (done) { | ||
it('sets the access token', function (done) { | ||
var token = "new token" | ||
client.setAccessToken(token) | ||
client._accessToken.should.be.String().and.equal(token) | ||
|
@@ -62,7 +62,7 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#getAuthorizationUrl', function () { | ||
|
||
it ('returns a valid URL for fetching', function (done) { | ||
it('returns a valid URL for fetching', function (done) { | ||
var state = "state" | ||
var redirectUrl = "https://example.com/callback" | ||
var scope = [medium.Scope.BASIC_PROFILE, medium.Scope.LIST_PUBLICATIONS, medium.Scope.PUBLISH_POST] | ||
|
@@ -71,20 +71,20 @@ describe('MediumClient - methods', function () { | |
authUrl.protocol.should.equal('https:') | ||
authUrl.hostname.should.equal('medium.com') | ||
authUrl.pathname.should.equal('/m/oauth/authorize') | ||
authUrl.query.should.deepEqual({ | ||
should.equal(JSON.stringify(authUrl.query), JSON.stringify({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is where I changed, others are indentation fixes, deepEqual not working with objects, don't know, are they checking the reference as well. So I had to do JSON.stringify! |
||
client_id: clientId, | ||
scope: scope.join(','), | ||
response_type: 'code', | ||
state: state, | ||
redirect_uri: redirectUrl | ||
}) | ||
})); | ||
done() | ||
}) | ||
}) | ||
|
||
describe('#exchangeAuthorizationCode', function () { | ||
|
||
it ('makes a request for authorization_code and sets the access token from response', function (done) { | ||
it('makes a request for authorization_code and sets the access token from response', function (done) { | ||
var code = '12345' | ||
var grantType = 'authorization_code' | ||
var redirectUrl = 'https://example.com/callback' | ||
|
@@ -105,8 +105,8 @@ describe('MediumClient - methods', function () { | |
refresh_token: refreshToken | ||
} | ||
var request = nock('https://api.medium.com/', { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}) | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}) | ||
.post('/v1/tokens', requestBody) | ||
.reply(201, responseBody) | ||
|
||
|
@@ -122,7 +122,7 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#exchangeRefreshToken', function () { | ||
|
||
it ('makes a request for authorization_code and sets the access token from response', function (done) { | ||
it('makes a request for authorization_code and sets the access token from response', function (done) { | ||
var refreshToken = 'fedcba' | ||
var accessToken = 'lkjihg' | ||
|
||
|
@@ -139,8 +139,8 @@ describe('MediumClient - methods', function () { | |
refresh_token: refreshToken | ||
} | ||
var request = nock('https://api.medium.com/', { | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}) | ||
'Content-Type': 'application/x-www-form-urlencoded' | ||
}) | ||
.post('/v1/tokens', requestBody) | ||
.reply(201, responseBody) | ||
|
||
|
@@ -155,7 +155,7 @@ describe('MediumClient - methods', function () { | |
}) | ||
|
||
describe('#getUser', function () { | ||
it ('gets the information from expected URL and returns contents of data envelope', function (done) { | ||
it('gets the information from expected URL and returns contents of data envelope', function (done) { | ||
var response = { data: 'response data' } | ||
|
||
var request = nock('https://api.medium.com') | ||
|
@@ -173,20 +173,20 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#getPublicationsForUser', function () { | ||
|
||
it ('throws a MediumError when no user ID is provided', function (done) { | ||
it('throws a MediumError when no user ID is provided', function (done) { | ||
(function () { client.getPublicationsForUser({}) }).should.throw(medium.MediumError) | ||
done() | ||
}) | ||
|
||
it ('makes a proper GET request to the Medium API and returns contents of data envelope when valid options are provided', function (done) { | ||
it('makes a proper GET request to the Medium API and returns contents of data envelope when valid options are provided', function (done) { | ||
var userId = '123456' | ||
var response = { data: 'response data' } | ||
|
||
var request = nock('https://api.medium.com/') | ||
.get('/v1/users/' + userId + '/publications') | ||
.reply(200, response) | ||
|
||
client.getPublicationsForUser({userId: userId}, function (err, data) { | ||
client.getPublicationsForUser({ userId: userId }, function (err, data) { | ||
if (err) throw err | ||
data.should.deepEqual(response['data']) | ||
done() | ||
|
@@ -197,12 +197,12 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#getContributorsForPublication', function () { | ||
|
||
it ('throws a MediumError when no publication ID is provided', function (done) { | ||
it('throws a MediumError when no publication ID is provided', function (done) { | ||
(function () { client.getContributorsForPublication({}) }).should.throw(medium.MediumError) | ||
done() | ||
}) | ||
|
||
it ('makes a proper GET request to the Medium API and returns contents of data envelope', function (done) { | ||
it('makes a proper GET request to the Medium API and returns contents of data envelope', function (done) { | ||
var options = { publicationId: 'abcdef' } | ||
var response = { data: 'response data' } | ||
var request = nock('https://api.medium.com/') | ||
|
@@ -220,7 +220,7 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#createPost', function () { | ||
|
||
it ('makes a proper POST request to the Medium API and returns contents of data envelope', function (done) { | ||
it('makes a proper POST request to the Medium API and returns contents of data envelope', function (done) { | ||
var options = { | ||
userId: '123456', | ||
title: 'new post title', | ||
|
@@ -235,14 +235,14 @@ describe('MediumClient - methods', function () { | |
var response = { data: 'response data' } | ||
var request = nock('https://api.medium.com/') | ||
.post('/v1/users/' + options.userId + '/posts', { | ||
title: options.title, | ||
content: options.content, | ||
contentFormat: options.contentFormat, | ||
tags: options.tags, | ||
canonicalUrl: options.canonicalUrl, | ||
publishedAt: options.publishedAt, | ||
publishStatus: options.publishStatus, | ||
license: options.license | ||
title: options.title, | ||
content: options.content, | ||
contentFormat: options.contentFormat, | ||
tags: options.tags, | ||
canonicalUrl: options.canonicalUrl, | ||
publishedAt: options.publishedAt, | ||
publishStatus: options.publishStatus, | ||
license: options.license | ||
}) | ||
.reply(200, response) | ||
|
||
|
@@ -257,12 +257,12 @@ describe('MediumClient - methods', function () { | |
|
||
describe('#createPostInPublication', function () { | ||
|
||
it ('should throw an error when no publication ID is provided', function (done) { | ||
it('should throw an error when no publication ID is provided', function (done) { | ||
(function () { client.createPostInPublication({}) }).should.throw(medium.MediumError) | ||
done() | ||
}) | ||
|
||
it ('makes a proper POST request to the Medium API and returns contents of data envelope', function (done) { | ||
it('makes a proper POST request to the Medium API and returns contents of data envelope', function (done) { | ||
var options = { | ||
publicationId: 'abcdef', | ||
title: 'new post title', | ||
|
@@ -277,14 +277,14 @@ describe('MediumClient - methods', function () { | |
var response = { data: 'response data' } | ||
var request = nock('https://api.medium.com/') | ||
.post('/v1/publications/' + options.publicationId + '/posts', { | ||
title: options.title, | ||
content: options.content, | ||
contentFormat: options.contentFormat, | ||
tags: options.tags, | ||
canonicalUrl: options.canonicalUrl, | ||
publishedAt: options.publishedAt, | ||
publishStatus: options.publishStatus, | ||
license: options.license | ||
title: options.title, | ||
content: options.content, | ||
contentFormat: options.contentFormat, | ||
tags: options.tags, | ||
canonicalUrl: options.canonicalUrl, | ||
publishedAt: options.publishedAt, | ||
publishStatus: options.publishStatus, | ||
license: options.license | ||
}) | ||
.reply(200, response) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a npm command so anyone can run
npm run test