Skip to content

Commit

Permalink
fix: Add changes under dev flag and fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pankajjs committed Jan 9, 2025
1 parent 51e56a2 commit f5bb6a0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
12 changes: 9 additions & 3 deletions models/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export const updateRequest = async (id: string, body: any, lastModifiedBy: strin

export const getRequests = async (query: any) => {
let { id, type, requestedBy, state, prev, next, page, size = SIZE } = query;
const dev = query.dev === "true";

size = parseInt(size);
page = parseInt(page);
try {
Expand All @@ -86,11 +88,15 @@ export const getRequests = async (query: any) => {
...requestDoc.data(),
};
}

if (requestedBy) {

if(requestedBy && dev){
requestQuery = requestQuery.where("requestedBy", "==", requestedBy);
}
else if (requestedBy) {
const requestedByUserId = await getUserId(requestedBy);
requestQuery = requestQuery.where("requestedBy", "in", [requestedByUserId, requestedBy]);
requestQuery = requestQuery.where("requestedBy", "==", requestedByUserId);
}

if (type) {
requestQuery = requestQuery.where("type", "==", type);
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/onboardingExtension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ describe("/requests Onboarding Extension", () => {
it("should fetch onboarding extension request by requestedBy field", (done) => {
requestsQuery.createRequest({ type: REQUEST_TYPE.ONBOARDING, requestedBy: username });
chai.request(app)
.get(`${getEndpoint}?requestedBy=${username}&type=ONBOARDING`)
.get(`${getEndpoint}?requestedBy=${username}&type=ONBOARDING&dev=true`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(200);
Expand Down
2 changes: 1 addition & 1 deletion test/unit/models/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe("models/oooRequests", () => {
it("Should return a list of all the requests by specific user ", async () => {
const oooRequestBodyData = { ...createOooRequests, requestedBy: testUserId };
await createRequest(oooRequestBodyData);
const query = { dev: "true", requestedBy: userData[16].username };
const query = { requestedBy: userData[16].username };
const oooRequestData = await getRequests(query);
expect(oooRequestData.allRequests).to.have.lengthOf(1);
expect(oooRequestData.allRequests[0].requestedBy).to.be.equal(testUserId);
Expand Down

0 comments on commit f5bb6a0

Please sign in to comment.