Skip to content

Commit

Permalink
[FEATURE] Check authentication for Talawa-admin added (#713)
Browse files Browse the repository at this point in the history
* check authentication feature added for talawa admin

* tests for check authentication added

* minor fixes

* typo fixes

* minor fixes

* npm err fixes
  • Loading branch information
asmitsirohi authored Jun 13, 2022
1 parent 11ead17 commit f395447
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lib/resolvers/Query.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,16 @@ const userLanguage = require('../resolvers/user_query/userLanguage');
const getlanguage = require('../resolvers/language_maintainer_query/getlanguage');
const directChatsByUserID = require('./direct_chat_query/directChatsByUserID');
const directChatsMessagesByChatID = require('./direct_chat_query/directChatsMessagesByChatID');
const checkAuth = require('./auth_query/checkAuth');

const Query = {
me,
user,
users,
usersConnection,

checkAuth,

organizations,
organizationsConnection,
organizationsMemberConnection,
Expand Down
12 changes: 12 additions & 0 deletions lib/resolvers/auth_query/checkAuth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const userExists = require('../../helper_functions/userExists');
const { USER_NOT_FOUND } = require('../../../constants');

module.exports = async (parent, args, context) => {
let userFound = await userExists(context.userId);
if (!userFound) throw new Error(USER_NOT_FOUND);

return {
...userFound?._doc,
organizationsBlockedBy: [],
};
};
2 changes: 2 additions & 0 deletions lib/schema/query.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ module.exports = `
users(where: UserWhereInput, orderBy: UserOrderByInput): [User] @auth
usersConnection(where: UserWhereInput, first: Int, skip: Int, orderBy: UserOrderByInput): [User]! @auth

checkAuth: User! @auth

organizations(id: ID, orderBy: OrganizationOrderByInput): [Organization]
organizationsConnection(where: OrganizationWhereInput, first: Int, skip: Int, orderBy: OrganizationOrderByInput): [Organization]!
organizationsMemberConnection(orgId:ID!, where: UserWhereInput, first: Int, skip: Int, orderBy: UserOrderByInput): UserConnection! @auth
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"start-test-server-in-action": "cross-env NODE_ENV=test pm2 start index.js -f",
"stop-test-server-in-action": "pm2 delete all",
"lint": "eslint . --fix && echo 'Lint complete.'",
"setup": "npm i [email protected] [email protected] inquirer markdown-js [email protected] [email protected] [email protected] -f && node setup.js",
"setup": "npm i [email protected] [email protected] inquirer markdown-js [email protected] [email protected] [email protected] && node setup.js",
"file-coverage": "npm test $npm_config_testfile -- --coverage --collectCoverageFrom=$npm_config_functionfile"
},
"repository": {
Expand Down Expand Up @@ -56,11 +56,11 @@
"helmet": "^4.6.0",
"i18n": "^0.13.3",
"image-hash": "^4.0.1",
"inquirer": "^8.2.0",
"inquirer": "^8.2.4",
"jsonwebtoken": "^8.5.1",
"logger": "file:lib/helper_lib/logger",
"markdown-js": "^0.0.4",
"marked": "^4.0.10",
"marked": "^2.0.1",
"marked-terminal": "^4.1.0",
"moment": "^2.29.2",
"mongoose": "^5.13.0",
Expand Down
32 changes: 32 additions & 0 deletions tests/resolvers/auth_query/checkAuth.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const shortid = require('shortid');

const database = require('../../../db');
const getUserId = require('../../functions/getUserIdFromSignup');
const checkAuth = require('../../../lib/resolvers/auth_query/checkAuth');

let userId;

beforeAll(async () => {
require('dotenv').config();
await database.connect();
let generatedEmail = `${shortid.generate().toLowerCase()}@test.com`;
userId = await getUserId(generatedEmail);
});

afterAll(() => {
database.disconnect();
});

describe('Testing check auth resolver', () => {
test('Testing if the user logged in or not', async () => {
const args = {
id: '62277875e904753262f99bc3',
};

const response = await checkAuth({}, args, {
userId: userId,
});

expect(response).toBeTruthy();
});
});

0 comments on commit f395447

Please sign in to comment.