From 5b949c8e26ab407e7ccd113e6d332ab3cb132fbb Mon Sep 17 00:00:00 2001 From: Akatsuki Levi Date: Mon, 18 Mar 2019 11:50:02 -0300 Subject: [PATCH] JSON.parse error fix --- examples/getComUsers.js | 18 +++---- modules/getComUsers.js | 70 ++++++++++++------------- test/modules/getCommentFromPost.test.js | 42 +++++++-------- test/modules/postBlog.test.js | 28 +++++----- 4 files changed, 79 insertions(+), 79 deletions(-) diff --git a/examples/getComUsers.js b/examples/getComUsers.js index 5efdde2..5980010 100644 --- a/examples/getComUsers.js +++ b/examples/getComUsers.js @@ -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) })(); \ No newline at end of file diff --git a/modules/getComUsers.js b/modules/getComUsers.js index 3a6851e..b3d1904 100644 --- a/modules/getComUsers.js +++ b/modules/getComUsers.js @@ -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; }; \ No newline at end of file diff --git a/test/modules/getCommentFromPost.test.js b/test/modules/getCommentFromPost.test.js index d4e8507..c63cc70 100644 --- a/test/modules/getCommentFromPost.test.js +++ b/test/modules/getCommentFromPost.test.js @@ -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(); } \ No newline at end of file diff --git a/test/modules/postBlog.test.js b/test/modules/postBlog.test.js index b118195..03a6a0c 100644 --- a/test/modules/postBlog.test.js +++ b/test/modules/postBlog.test.js @@ -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(); } \ No newline at end of file