Skip to content

Commit

Permalink
Merge pull request #96 from VenkatKadiveti/r4.10-testcases
Browse files Browse the repository at this point in the history
Issue #SB-30073 fix: Test cases
  • Loading branch information
reshmi-nair authored Jul 14, 2022
2 parents c20e69c + 8eb105a commit dab1cb4
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 3 deletions.
4 changes: 2 additions & 2 deletions helpers/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const notificationObj = async (req, resp) => {
}
return keyVal;
})
console.log('notification payload-----------', JSON.stringify(result))
return result;
}

function getValue(resp, val) {
Expand All @@ -48,7 +48,7 @@ async function getUserObject(req, fromUid, toUid) {
}

function getSunbirdIds(req, uids) {
const url = `${req.protocol}://${req.get('host')}/discussion/forum/v2/users/details`;
const url = `${req.protocol}://${req.host}/discussion/forum/v2/users/details`;
const payload = {
request: {
uids: uids
Expand Down
47 changes: 47 additions & 0 deletions tests/spec/audit.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,51 @@ describe("Audit Event Unit Tests", function () {
expect(audit.auditEventObject._pdata.id).to.equal('discussion-middleware');
expect(audit.auditEventObject._pdata.ver).to.equal('4.6.0');
});

it("should get reqData", async function () {
const data = audit.auditEventObject.reqData;
expect(audit.auditEventObject._pdata.pid).to.equal('staging.sunbird.portal');
expect(audit.auditEventObject._pdata.id).to.equal('discussion-middleware');
expect(audit.auditEventObject._pdata.ver).to.equal('4.6.0');
});

it("should set actor", async function () {
audit.auditEventObject.actor = req;
expect(audit.auditEventObject._actor.id).to.equal('public');
expect(audit.auditEventObject._actor.type).to.equal('User');
});

it("should get actor", async function () {
const actor = audit.auditEventObject.actor;
expect(actor.id).to.equal('public');
expect(actor.type).to.equal('User');
});

it("should set channel", async function () {
audit.auditEventObject.channel = req;
console.log(audit.auditEventObject)
expect(audit.auditEventObject._channel).to.equal('f5db7376-265c-a244-952b-86672b05e070');
});

it("should get channel", async function () {
const channel = audit.auditEventObject.channel;
expect(channel).to.equal('f5db7376-265c-a244-952b-86672b05e070');
});

it("should get pdata", async function () {
const pdata = audit.auditEventObject.pdata;
expect(pdata.pid).to.equal('staging.sunbird.portal');
expect(pdata.id).to.equal('discussion-middleware');
expect(pdata.ver).to.equal('4.6.0');
});

it("should set rollup", async function () {
audit.auditEventObject.rollup = req;
expect(audit.auditEventObject._rollup.l1).to.equal('f5db7376-265c-a244-952b-86672b05e070');
});

it("should get rollup", async function () {
const rollup = audit.auditEventObject.rollup;
expect(rollup.l1).to.equal('f5db7376-265c-a244-952b-86672b05e070');
});
});
74 changes: 73 additions & 1 deletion tests/spec/mock.data.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1729,5 +1729,77 @@ module.exports = {
"timestampISO": "2022-07-04T07:06:02.686Z"
}
}
}
},
forumUserDetails: {
"id": ".discussions.api.forum.v2.users.details",
"ver": "1.0",
"ets": 1657779480494,
"params": {
"resmsgid": "1f590939-21b9-41b0-9f28-8d2a8a0968e6",
"msgid": "",
"status": "Success"
},
"responseCode": "OK",
"result": [
{
"uid": 2,
"username": "content_creator_tn3941",
"userslug": "content_creator_tn3941",
"email": "content_creator_tn3941@staging.sunbirded.org",
"email:confirmed": 0,
"joindate": 1635143407282,
"lastonline": 1649328288672,
"picture": null,
"icon:bgColor": "#795548",
"fullname": null,
"location": null,
"birthday": null,
"website": null,
"aboutme": null,
"signature": null,
"uploadedpicture": null,
"profileviews": 1,
"reputation": -6,
"postcount": 118,
"topiccount": 70,
"lastposttime": 1646305551002,
"banned": false,
"banned:expire": 0,
"status": "offline",
"flags": null,
"followerCount": 0,
"followingCount": 0,
"cover:url": null,
"cover:position": null,
"groupTitle": null,
"sunbird-oidcId": "4cd4c690-eab6-4938-855a-447c7b1b8ea9",
"displayname": "content_creator_tn3941",
"groupTitleArray": [],
"icon:text": "C",
"joindateISO": "2021-10-25T06:30:07.282Z",
"lastonlineISO": "2022-04-07T10:44:48.672Z",
"banned_until": 0,
"banned_until_readable": "Not Banned"
}
]
},
userVoteRes: {
"code": "ok",
"payload": {
"user": {
"reputation": -36
},
"fromuid": 10,
"post": {
"pid": 123,
"uid": 3,
"tid": 84,
"upvotes": 1,
"downvotes": 0,
"votes": 1
},
"upvote": true,
"downvote": false
}
}
}
42 changes: 42 additions & 0 deletions tests/spec/notification.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const notification = require('../../helpers/notification');
const { expect } = require("chai");
const mock = require('./mock.data.spec')
const nodebbUrl = 'https://staging.sunbirded.org/discussion';
const nock = require('nock');
const chai = require('chai');
let chaiHttp = require('chai-http');
chai.should();
chai.use(chaiHttp);
let server = require('../../app');

describe("Notification helper Unit Tests", function () {
const payload = {
"request": {
"uids": [10, 3]
}
};
const request = chai.request(server);
request.route = { path: '/discussion/v2/posts/:pid/vote' };
request.protocol = 'https';
request.host = "staging.sunbirded.org";
request.body = payload;
request.headers = {
'x-request-id': 'f5db7376-265c-a244-952b-86672b05e070',
'x-channel-id': 'f5db7376-265c-a244-952b-86672b05e070',
'x-app-id': 'staging.sunbird.portal',
'x-session-id': 'eMoOr4TgLbHX8cknf3j_VL_AQfM83Ph5'
};

it("should call notificationObj function and set notification data", async function () {

nock(nodebbUrl)
.post('/forum/v2/users/details', payload)
.reply(200, mock.forumUserDetails);

const result = await notification.notificationObj(request, mock.userVoteRes);
expect(result.headers.sid).to.equal('eMoOr4TgLbHX8cknf3j_VL_AQfM83Ph5');
expect(result.headers.traceID).to.equal('f5db7376-265c-a244-952b-86672b05e070');
expect(result.notificationData.ids[0]).to.equal('4cd4c690-eab6-4938-855a-447c7b1b8ea9')

});
});

0 comments on commit dab1cb4

Please sign in to comment.