Skip to content

Commit

Permalink
JSON.parse error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
akatsukilevi committed Mar 18, 2019
1 parent 43f4723 commit 5b949c8
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 79 deletions.
18 changes: 9 additions & 9 deletions examples/getComUsers.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
console.log("Get a payload of message inside one one species chat room");
const env = require('./env');
const Amino = require('../index');
(async function () {
const sid = await Amino.login(env.email, env.password);
const myCommunities = await Amino.getJoinedComs();
const firstCommunity = myCommunities.coms[0];
const users = await Amino.getComUsers(firstCommunity.id);
console.log(users)
console.log("Get a payload of message inside one one species chat room");
const env = require('./env');
const Amino = require('../index');
(async function () {
const sid = await Amino.login(env.email, env.password);
const myCommunities = await Amino.getJoinedComs();
const firstCommunity = myCommunities.coms[0];
const users = await Amino.getComUsers(firstCommunity.id);
console.log(users)
})();
70 changes: 35 additions & 35 deletions modules/getComUsers.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
const fetch = require('isomorphic-fetch');
const endpoints = require('../helpers/endpoints.js'); //For Creating shorter URL's in this Module
const objs = require('../helpers/objects.js'); //For Storing the Objects that the Framework returns.
const { getConfig, errorMessages } = require('../index');

/**
* Gets a JSON-Object were all Community ID's, Name's and URL's for the current Logged-In Account are obainted in.
* @param {SecurityString} sid For authenticating with the Narvii-API.
* @returns {Object} Object containing all Joined Coms with the Logged in Account.
*/

module.exports = async function getComUsers(communityId) {
let communityUsers = objs.communityUsers;
communityUsers.users = [];
const sid = getConfig('sid');
if (typeof sid != 'string') {
throw new Error(errorMessages.missingSid);
}
try {
const response = await fetch(endpoints.getComUsers(communityId), {
headers: {
'NDCAUTH': `sid=${sid}`
}
});
const body = await response.json();
communityUsers.users = body.userProfileList;
communityUsers.count = body.userProfileCount;
communityUsers.error = null;
communityUsers.status = 'ok';
}
catch (err) {
communityUsers.error = err;
throw 'Error while calling getComUsers: ' + err;
}
return communityUsers;
const fetch = require('isomorphic-fetch');
const endpoints = require('../helpers/endpoints.js'); //For Creating shorter URL's in this Module
const objs = require('../helpers/objects.js'); //For Storing the Objects that the Framework returns.
const { getConfig, errorMessages } = require('../index');

/**
* Gets a JSON-Object were all Community ID's, Name's and URL's for the current Logged-In Account are obainted in.
* @param {SecurityString} sid For authenticating with the Narvii-API.
* @returns {Object} Object containing all Joined Coms with the Logged in Account.
*/

module.exports = async function getComUsers(communityId) {
let communityUsers = objs.communityUsers;
communityUsers.users = [];
const sid = getConfig('sid');
if (typeof sid != 'string') {
throw new Error(errorMessages.missingSid);
}
try {
const response = await fetch(endpoints.getComUsers(communityId), {
headers: {
'NDCAUTH': `sid=${sid}`
}
});
const body = await response.json();
communityUsers.users = body.userProfileList;
communityUsers.count = body.userProfileCount;
communityUsers.error = null;
communityUsers.status = 'ok';
}
catch (err) {
communityUsers.error = err;
throw 'Error while calling getComUsers: ' + err;
}
return communityUsers;
};
42 changes: 21 additions & 21 deletions test/modules/getCommentFromPost.test.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
if(process.env.TRAVIS_PULL_REQUEST === 'false' || typeof process.env.TRAVIS_PULL_REQUEST === 'undefined'){
require('../helpers/loadEnv');
describe('how the methods should response (With NO false input)', () => {
it('Get the latest blog feed of one specie community', async () => {
const Amino = require('../../index');
const sid = await Amino.login(process.env.AMINO_EMAIL, process.env.AMINO_PASSWORD);
const myCommunities = await Amino.getJoinedComs();
const firstCommunity = myCommunities.coms[0];
const myCommunityBlogFeed = await Amino.getComBlogFeed(firstCommunity.id);
const comments = await Amino.getCommentsPost(firstCommunity.id, myCommunityBlogFeed.blogs[0].blogId);
expect(comments.comments).toBeDefined();
expect(
Array.isArray(comments.comments)
)
.toBe(true);
expect(comments.status).toBe('ok');
expect(comments.error).toBeNull();
});
});
}else{
describe.skip();
if(process.env.TRAVIS_PULL_REQUEST === 'false' || typeof process.env.TRAVIS_PULL_REQUEST === 'undefined'){
require('../helpers/loadEnv');
describe('how the methods should response (With NO false input)', () => {
it('Get the latest blog feed of one specie community', async () => {
const Amino = require('../../index');
const sid = await Amino.login(process.env.AMINO_EMAIL, process.env.AMINO_PASSWORD);
const myCommunities = await Amino.getJoinedComs();
const firstCommunity = myCommunities.coms[0];
const myCommunityBlogFeed = await Amino.getComBlogFeed(firstCommunity.id);
const comments = await Amino.getCommentsPost(firstCommunity.id, myCommunityBlogFeed.blogs[0].blogId);
expect(comments.comments).toBeDefined();
expect(
Array.isArray(comments.comments)
)
.toBe(true);
expect(comments.status).toBe('ok');
expect(comments.error).toBeNull();
});
});
}else{
describe.skip();
}
28 changes: 14 additions & 14 deletions test/modules/postBlog.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
if(process.env.TRAVIS_PULL_REQUEST === 'false' || typeof process.env.TRAVIS_PULL_REQUEST === 'undefined'){
require('../helpers/loadEnv');
describe('how the methods should response (With NO false input)', () => {
it('should post a Blog into a given Community', async () => {
const Amino = require('../../index');
const sid = await Amino.login(process.env.AMINO_EMAIL, process.env.AMINO_PASSWORD);
const blog = await Amino.postBlog(process.env.AMINO_DEBUG_COMMUNITY, `Debug Testcase ${process.env.TRAVIS_JOB_ID}`, `The Commitname was: ${process.env.TRAVIS_COMMIT} and the Message was: ${process.env.TRAVIS_COMMIT_MESSAGE}`);
expect(blog.blog).toBeDefined();
expect(blog.status).toBe('ok');
expect(blog.error).toBeNull();
});
});
}else{
describe.skip();
if(process.env.TRAVIS_PULL_REQUEST === 'false' || typeof process.env.TRAVIS_PULL_REQUEST === 'undefined'){
require('../helpers/loadEnv');
describe('how the methods should response (With NO false input)', () => {
it('should post a Blog into a given Community', async () => {
const Amino = require('../../index');
const sid = await Amino.login(process.env.AMINO_EMAIL, process.env.AMINO_PASSWORD);
const blog = await Amino.postBlog(process.env.AMINO_DEBUG_COMMUNITY, `Debug Testcase ${process.env.TRAVIS_JOB_ID}`, `The Commitname was: ${process.env.TRAVIS_COMMIT} and the Message was: ${process.env.TRAVIS_COMMIT_MESSAGE}`);
expect(blog.blog).toBeDefined();
expect(blog.status).toBe('ok');
expect(blog.error).toBeNull();
});
});
}else{
describe.skip();
}

1 comment on commit 5b949c8

@akatsukilevi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AAAAAA i commited wrong, lost all the changes i made!

Please sign in to comment.