Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ app.use(function (req, res, next) {
});

// error handler
app.use(function (err, req, res, next) {
app.use(function (err, req, res, _next) {
if (isMulterError(err)) {
multerErrorHandling(err, req, res);
} else {
res.boom.notFound(err);
return multerErrorHandling(err, req, res);
}
return res.boom.boomify(err, {
statusCode: err.statusCode,
});
});

module.exports = app;
2 changes: 1 addition & 1 deletion controllers/extensionRequests.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ const createTaskExtensionRequest = async (req, res) => {
*/
const fetchExtensionRequests = async (req, res) => {
try {
const { cursor, size, order } = req.query;
const { cursor, size = 5, order } = req.query;
const { status, taskId, assignee } = parseQueryParams(req._parsedUrl.search);
const { transformedSize, transformedStatus } = transformQuery(size, status);

Expand Down
7 changes: 0 additions & 7 deletions controllers/onboardingExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ export const updateOnboardingExtensionRequestState = async (
req: UpdateOnboardingExtensionStateRequest,
res: OnboardingExtensionResponse )
: Promise<OnboardingExtensionResponse> => {

const dev = req.query.dev === "true";

if(!dev) return res.boom.notImplemented("Feature not implemented");

const body = req.body as UpdateOnboardingExtensionStateRequestBody;
const lastModifiedBy = req?.userData?.id;
Expand Down Expand Up @@ -224,9 +220,6 @@ export const updateOnboardingExtensionRequestController = async (
const id = req.params.id;
const lastModifiedBy = req?.userData?.id;
const isSuperuser = req?.userData?.roles?.super_user === true;
const dev = req.query.dev === "true";

if(!dev) return res.boom.notImplemented("Feature not implemented");

try{
const extensionRequestDoc = await requestModel.doc(id).get();
Expand Down
8 changes: 1 addition & 7 deletions middlewares/skipAuthenticateForOnboardingExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,11 @@ import { REQUEST_TYPE } from "../constants/requests";
export const skipAuthenticateForOnboardingExtensionRequest = (authenticate, verifyDiscordBot) => {
return async (req: Request, res: Response, next: NextFunction) => {
const type = req.body.type;
const dev = req.query.dev;

if(type === REQUEST_TYPE.ONBOARDING){
if (dev != "true"){
return res.status(501).json({
message: "Feature not implemented"
})
}
return await verifyDiscordBot(req, res, next);
}

return await authenticate(req, res, next)
}
}
}
6 changes: 1 addition & 5 deletions models/progresses.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,11 @@
* @throws {Error} If the userId or taskId is invalid or does not exist.
**/
const getProgressDocument = async (queryParams) => {
const { dev } = queryParams;
await assertUserOrTaskExists(queryParams);
const query = buildQueryToFetchDocs(queryParams);
const progressDocs = await getProgressDocs(query);

if (dev === "true") {
return await addUserDetailsToProgressDocs(progressDocs);
}
return progressDocs;
return await addUserDetailsToProgressDocs(progressDocs);
};

/**
Expand Down Expand Up @@ -104,8 +100,8 @@
async function getProgressByDate(pathParams, queryParams) {
const { type, typeId, date } = pathParams;
const { dev } = queryParams;
await assertUserOrTaskExists({ [TYPE_MAP[type]]: typeId });

Check warning on line 103 in models/progresses.js

View workflow job for this annotation

GitHub Actions / build (22.10.0)

Generic Object Injection Sink
const query = buildQueryToSearchProgressByDay({ [TYPE_MAP[type]]: typeId, date });

Check warning on line 104 in models/progresses.js

View workflow job for this annotation

GitHub Actions / build (22.10.0)

Generic Object Injection Sink
const result = await query.get();
if (!result.size) {
throw new NotFound(PROGRESS_DOCUMENT_NOT_FOUND);
Expand Down
18 changes: 18 additions & 0 deletions test/integration/extensionRequests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,24 @@ describe("Extension Requests", function () {
});
});

it("should return 5 extension requests by default when size query is not provided", function (done) {
chai
.request(app)
.get(`/extension-requests`)
.set("cookie", `${cookieName}=${appOwnerjwt}`)
.end((err, res) => {
if (err) {
return done(err);
}
expect(res).to.have.status(200);
expect(res.body).to.be.a("object");
expect(res.body.message).to.be.equal("Extension Requests returned successfully!");
expect(res.body.allExtensionRequests).to.be.a("array");
expect(res.body.allExtensionRequests).to.have.lengthOf(5);
return done();
});
});

it("should return success response and all extension requests with query params", function (done) {
chai
.request(app)
Expand Down
86 changes: 24 additions & 62 deletions test/integration/onboardingExtension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe("/requests Onboarding Extension", () => {

it("should not call verifyDiscordBot and return 401 response when extension type is not onboarding", (done)=> {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.send({...body, type: REQUEST_TYPE.OOO})
.end((err, res)=>{
if(err) return done(err);
Expand All @@ -86,22 +86,10 @@ describe("/requests Onboarding Extension", () => {
})
})

it("should return Feature not implemented when dev is not true", (done) => {
chai.request(app)
.post(`${postEndpoint}`)
.send(body)
.end((err, res)=>{
if (err) return done(err);
expect(res.statusCode).to.equal(501);
expect(res.body.message).to.equal("Feature not implemented");
done();
})
})

it("should return Invalid Request when authorization header is missing", (done) => {
chai
.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", "")
.send(body)
.end((err, res) => {
Expand All @@ -114,7 +102,7 @@ describe("/requests Onboarding Extension", () => {

it("should return Unauthorized Bot for invalid token", (done) => {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${BAD_TOKEN}`)
.send(body)
.end((err, res) => {
Expand All @@ -127,7 +115,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response for invalid value type of numberOfDays", (done) => {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send({...body, numberOfDays:"1"})
.end((err, res) => {
Expand All @@ -141,7 +129,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response for invalid value of numberOfDays", (done) => {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send({...body, numberOfDays:1.4})
.end((err, res) => {
Expand All @@ -155,7 +143,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response for invalid userId", (done) => {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send({...body, userId: undefined})
.end((err, res) => {
Expand All @@ -172,7 +160,7 @@ describe("/requests Onboarding Extension", () => {
sinon.stub(requestsQuery, "createRequest")
.throws("Error while creating extension request");
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body)
.end((err, res)=>{
Expand All @@ -186,7 +174,7 @@ describe("/requests Onboarding Extension", () => {
it("should return 500 response when discordJoinedAt date string is invalid", (done) => {
createUserStatusWithState(testUserIdForInvalidDiscordJoinedDate, userStatusModel, userState.ONBOARDING);
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send({...body, userId: testUserDiscordIdForInvalidDiscordJoinedDate})
.end((err, res)=>{
Expand All @@ -199,7 +187,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 404 response when user does not exist", (done) => {
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send({...body, userId: "11111"})
.end((err, res) => {
Expand All @@ -214,7 +202,7 @@ describe("/requests Onboarding Extension", () => {
it("should return 403 response when user's status is not onboarding", (done)=> {
createUserStatusWithState(testUserId, userStatusModel, userState.ACTIVE);
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -231,7 +219,7 @@ describe("/requests Onboarding Extension", () => {
requestsQuery.createRequest({...extensionRequest, state: REQUEST_STATE.PENDING, userId: testUserId});

chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -246,7 +234,7 @@ describe("/requests Onboarding Extension", () => {
it("should return 201 for successful response when user has onboarding state", (done)=> {
createUserStatusWithState(testUserId, userStatusModel, userState.ONBOARDING);
chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -271,7 +259,7 @@ describe("/requests Onboarding Extension", () => {
});

const res = await chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body);

Expand All @@ -296,7 +284,7 @@ describe("/requests Onboarding Extension", () => {
});

const res = await chai.request(app)
.post(`${postEndpoint}?dev=true`)
.post(postEndpoint)
.set("authorization", `Bearer ${botToken}`)
.send(body);

Expand Down Expand Up @@ -418,7 +406,7 @@ describe("/requests Onboarding Extension", () => {
type: REQUEST_TYPE.ONBOARDING,
requestNumber: 2
});
putEndpoint = `/requests/${latestExtension.id}?dev=true`;
putEndpoint = `/requests/${latestExtension.id}`;
authToken = generateAuthToken({userId});
})

Expand All @@ -443,7 +431,7 @@ describe("/requests Onboarding Extension", () => {

it("should return Invalid request type for incorrect value of type", (done) => {
chai.request(app)
.put("/requests/1111?dev=true")
.put("/requests/1111")
.set("authorization", `Bearer ${authToken}`)
.send({...body, type: "<InvalidType>"})
.end((err, res)=>{
Expand All @@ -455,19 +443,6 @@ describe("/requests Onboarding Extension", () => {
})
})

it("should return Feature not implemented when dev is not true", (done) => {
chai.request(app)
.put(`/requests/1111?dev=false`)
.send(body)
.set("authorization", `Bearer ${authToken}`)
.end((err, res)=>{
if (err) return done(err);
expect(res.statusCode).to.equal(501);
expect(res.body.message).to.equal("Feature not implemented");
done();
})
})

it("should return Unauthenticated User when authorization header is missing", (done) => {
chai.request(app)
.put(putEndpoint)
Expand Down Expand Up @@ -510,7 +485,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 404 response for invalid extension id", (done) => {
chai.request(app)
.put(`/requests/1111?dev=true`)
.put(`/requests/1111`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand Down Expand Up @@ -538,7 +513,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response when extension state is approved", (done) => {
chai.request(app)
.put(`/requests/${latestApprovedExtension.id}?dev=true`)
.put(`/requests/${latestApprovedExtension.id}`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -552,7 +527,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response when extension state is rejected", (done) => {
chai.request(app)
.put(`/requests/${latestRejectedExtension.id}?dev=true`)
.put(`/requests/${latestRejectedExtension.id}`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand Down Expand Up @@ -646,7 +621,7 @@ describe("/requests Onboarding Extension", () => {
userId: userId
});
oooRequest = await requestsQuery.createRequest({type: REQUEST_TYPE.OOO, userId: userId});
patchEndpoint = `/requests/${latestValidExtension.id}?dev=true`;
patchEndpoint = `/requests/${latestValidExtension.id}`;
authToken = generateAuthToken({userId});
})

Expand All @@ -669,19 +644,6 @@ describe("/requests Onboarding Extension", () => {
})
})

it("should return Feature not implemented when dev is not true", (done) => {
chai.request(app)
.patch(`/requests/1111?dev=false`)
.send(body)
.set("authorization", `Bearer ${authToken}`)
.end((err, res)=>{
if (err) return done(err);
expect(res.statusCode).to.equal(501);
expect(res.body.message).to.equal("Feature not implemented");
done();
})
})

it("should return Unauthenticated User when authorization header is missing", (done) => {
chai
.request(app)
Expand Down Expand Up @@ -725,7 +687,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 404 response for invalid extension id", (done) => {
chai.request(app)
.patch(`/requests/1111?dev=true`)
.patch(`/requests/1111`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand Down Expand Up @@ -753,7 +715,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response when request type is not onboarding", (done) => {
chai.request(app)
.patch(`/requests/${oooRequest.id}?dev=true`)
.patch(`/requests/${oooRequest.id}`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -767,7 +729,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response when extension state is not pending", (done) => {
chai.request(app)
.patch(`/requests/${latestApprovedExtension.id}?dev=true`)
.patch(`/requests/${latestApprovedExtension.id}`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand All @@ -781,7 +743,7 @@ describe("/requests Onboarding Extension", () => {

it("should return 400 response when old dealdine is greater than new deadline", (done) => {
chai.request(app)
.patch(`/requests/${latestInvalidExtension.id}?dev=true`)
.patch(`/requests/${latestInvalidExtension.id}`)
.set("authorization", `Bearer ${authToken}`)
.send(body)
.end((err, res) => {
Expand Down
Loading
Loading