generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Integrate userData into Progresses API to reduce redundant calls (
#2311) * initial * fix typos * using batches to fetch userIds * refactor the function * added test for dev false case * added unit tests * fix response body containing email --------- Co-authored-by: Achintya Chatterjee <[email protected]> Co-authored-by: Prakash Choudhary <[email protected]>
- Loading branch information
1 parent
444e34c
commit 07b8720
Showing
6 changed files
with
283 additions
and
4 deletions.
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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
const chai = require("chai"); | ||
const sinon = require("sinon"); | ||
const { expect } = chai; | ||
const { addUserDetailsToProgressDocs } = require("../../../models/progresses"); | ||
const cleanDb = require("../../utils/cleanDb"); | ||
const users = require("../../../models/users"); | ||
const userDataArray = require("../../fixtures/user/user")(); | ||
const { removeSensitiveInfo } = require("../../../services/dataAccessLayer"); | ||
describe("getProgressDocument", function () { | ||
afterEach(function () { | ||
cleanDb(); | ||
sinon.restore(); | ||
}); | ||
|
||
it("should add userData to progress documents correctly", async function () { | ||
const userData = userDataArray[0]; | ||
const userData2 = userDataArray[1]; | ||
const { userId } = await users.addOrUpdate(userData); | ||
const { userId: userId2 } = await users.addOrUpdate(userData2); | ||
const updatedUserData = { ...userData, id: userId }; | ||
const updatedUserData2 = { ...userData2, id: userId2 }; | ||
removeSensitiveInfo(updatedUserData); | ||
removeSensitiveInfo(updatedUserData2); | ||
const mockProgressDocs = [ | ||
{ userId: userId, taskId: 101 }, | ||
{ userId: userId2, taskId: 102 }, | ||
]; | ||
|
||
const result = await addUserDetailsToProgressDocs(mockProgressDocs); | ||
|
||
expect(result).to.deep.equal([ | ||
{ userId, taskId: 101, userData: updatedUserData }, | ||
{ userId: userId2, taskId: 102, userData: updatedUserData2 }, | ||
]); | ||
}); | ||
|
||
it("should handle errors and set userData as null", async function () { | ||
const userData = userDataArray[0]; | ||
await users.addOrUpdate(userData); | ||
|
||
const mockProgressDocs = [{ userId: "userIdNotExists", taskId: 101 }]; | ||
|
||
const result = await addUserDetailsToProgressDocs(mockProgressDocs); | ||
|
||
expect(result).to.deep.equal([{ userId: "userIdNotExists", taskId: 101, userData: null }]); | ||
}); | ||
}); |