Skip to content

Commit

Permalink
Remove dev feature flag for POST /requests and PUT /requests/:id APIs (
Browse files Browse the repository at this point in the history
…#2153)

* chore: remove feature flag for POST /requests API

* chore: remove feature flag for PUT /requests/:id API

* chore: remove dev query param from request query type

* chore: remove empty query from POST /requests API middleware test
  • Loading branch information
samarpan1738 authored Sep 21, 2024
1 parent edadf41 commit a6814b6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 78 deletions.
8 changes: 0 additions & 8 deletions middlewares/validators/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ export const createRequestsMiddleware = async (
next: NextFunction
) => {
const type = req.body.type;
// TODO: Remove this check once feature is tested and ready to be used
if ( req.query.dev !== "true") {
return res.boom.badRequest("Please use feature flag to make this requests");
}

try {
switch (type) {
Expand Down Expand Up @@ -49,10 +45,6 @@ export const updateRequestsMiddleware = async (
res: CustomResponse,
next: NextFunction
) => {
// TODO: Remove this check once feature is tested and ready to be used
if ( req.query.dev !== "true") {
return res.boom.badRequest("Please use feature flag to make this requests");
}
const schema = joi
.object()
.strict()
Expand Down
98 changes: 35 additions & 63 deletions test/integration/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("/requests OOO", function () {
it("should return 401 if user is not logged in", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.send(validOooStatusRequests)
.end(function (err, res) {
expect(res).to.have.status(401);
Expand All @@ -82,7 +82,7 @@ describe("/requests OOO", function () {
it("should create a new request", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests)
.end(function (err, res) {
Expand All @@ -96,12 +96,12 @@ describe("/requests OOO", function () {
it("should return 400, if already created request is created again", async function () {
await chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests);
const response = await chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests);
expect(response).to.have.status(400);
Expand All @@ -112,7 +112,7 @@ describe("/requests OOO", function () {
it("should create a new request and have all the required fields in the response", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests)
.end(function (err, res) {
Expand All @@ -128,24 +128,10 @@ describe("/requests OOO", function () {
});
});

it("should return error if feature flag is not used", function (done) {
chai
.request(app)
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests)
.end(function (err, res) {
expect(res).to.have.status(400);
expect(res.body).to.have.property("message");
expect(res.body.message).to.equal("Please use feature flag to make this requests");
done();
});
});

it("should create a new request", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(validOooStatusRequests)
.end(function (err, res) {
Expand All @@ -160,7 +146,7 @@ describe("/requests OOO", function () {
const type = "ACTIVE";
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send({ ...validOooStatusRequests, type })
.end(function (err, res) {
Expand All @@ -174,7 +160,7 @@ describe("/requests OOO", function () {
it("should return error if message is not present in body", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send(_.omit(validOooStatusRequests, "message"))
.end(function (err, res) {
Expand All @@ -188,7 +174,7 @@ describe("/requests OOO", function () {
it("should return error if state in the body is not PENDING", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${authToken}`)
.send({ ...validOooStatusRequests, state: REQUEST_STATE.APPROVED })
.end(function (err, res) {
Expand All @@ -204,7 +190,7 @@ describe("/requests OOO", function () {
it("should return 401 if user is not logged in", function (done) {
chai
.request(app)
.put(`/requests/${oooRequestId}?dev=true`)
.put(`/requests/${oooRequestId}`)
.send(validOooStatusUpdate)
.end(function (err, res) {
expect(res).to.have.status(401);
Expand All @@ -215,7 +201,7 @@ describe("/requests OOO", function () {
it("should approved a request", function (done) {
chai
.request(app)
.put(`/requests/${pendingOooRequestId}?dev=true`)
.put(`/requests/${pendingOooRequestId}`)
.set("cookie", `${cookieName}=${superUserToken}`)
.send(validOooStatusUpdate)
.end(function (err, res) {
Expand All @@ -226,25 +212,11 @@ describe("/requests OOO", function () {
});
});

it("should update a request", function (done) {
chai
.request(app)
.put(`/requests/${pendingOooRequestId}`)
.set("cookie", `${cookieName}=${superUserToken}`)
.send(validOooStatusUpdate)
.end(function (err, res) {
expect(res).to.have.status(400);
expect(res.body).to.have.property("message");
expect(res.body.message).to.equal("Please use feature flag to make this requests");
done();
});
});

it("should return error if wrong type is passed", function (done) {
const type = "ACTIVE";
chai
.request(app)
.put(`/requests/${pendingOooRequestId}?dev=true`)
.put(`/requests/${pendingOooRequestId}`)
.set("cookie", `${cookieName}=${superUserToken}`)
.send({ ...validOooStatusUpdate, type })
.end(function (err, res) {
Expand All @@ -258,7 +230,7 @@ describe("/requests OOO", function () {
it("should return 404 if request does not exist", function (done) {
chai
.request(app)
.put(`/requests/invalidoooRequestId?dev=true`)
.put(`/requests/invalidoooRequestId`)
.set("cookie", `${cookieName}=${superUserToken}`)
.send(validOooStatusUpdate)
.end(function (err, res) {
Expand All @@ -272,7 +244,7 @@ describe("/requests OOO", function () {
it("should return 400 if request is already approved", function (done) {
chai
.request(app)
.put(`/requests/${approvedOooRequestId}?dev=true`)
.put(`/requests/${approvedOooRequestId}`)
.set("cookie", `${cookieName}=${superUserToken}`)
.send(validOooStatusUpdate)
.end(function (err, res) {
Expand Down Expand Up @@ -455,7 +427,7 @@ describe("/requests Extension", function () {
it("should return 401(Unauthorized) if user is not logged in", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.send(extensionRequest)
.end(function (err, res) {
expect(res).to.have.status(401);
Expand All @@ -469,7 +441,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -487,7 +459,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -505,7 +477,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken2}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -523,7 +495,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -541,7 +513,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -560,7 +532,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj)
.end(function (err, res) {
Expand All @@ -578,7 +550,7 @@ describe("/requests Extension", function () {
};
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj)
.end(async function (err, res) {
Expand All @@ -592,7 +564,7 @@ describe("/requests Extension", function () {
};
const response = await chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(extensionRequestObj2);
expect(response).to.have.status(400);
Expand Down Expand Up @@ -642,7 +614,7 @@ describe("/requests Extension", function () {
it("should return 401(Unauthorized) if user is not logged in", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
expect(res).to.have.status(401);
Expand All @@ -655,7 +627,7 @@ describe("/requests Extension", function () {
it("should return 401 if user is not super user", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
Expand All @@ -669,7 +641,7 @@ describe("/requests Extension", function () {
it("should return 400(Bad Request) if request is already approved", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
Expand All @@ -680,7 +652,7 @@ describe("/requests Extension", function () {

chai
.request(app)
.put(`/requests/${id}?dev=true`)
.put(`/requests/${id}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
Expand All @@ -695,7 +667,7 @@ describe("/requests Extension", function () {
it("should return 400(Bad Request) if request is already rejected", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(rejectedExtensionRequest)
.end(function (err, res) {
Expand All @@ -706,7 +678,7 @@ describe("/requests Extension", function () {

chai
.request(app)
.put(`/requests/${id}?dev=true`)
.put(`/requests/${id}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(rejectedExtensionRequest)
.end(function (err, res) {
Expand All @@ -721,7 +693,7 @@ describe("/requests Extension", function () {
it("should approve an extension request", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
Expand All @@ -733,7 +705,7 @@ describe("/requests Extension", function () {
it("should return 400(Bad Request) if invalid state is passed", function (done) {
chai
.request(app)
.put(`/requests/${pendingExtensionRequestId}?dev=true`)
.put(`/requests/${pendingExtensionRequestId}`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(invalidExtensionRequest)
.end(function (err, res) {
Expand All @@ -747,7 +719,7 @@ describe("/requests Extension", function () {
it("should return 404(Not Found) if request does not exist", function (done) {
chai
.request(app)
.put(`/requests/randomId?dev=true`)
.put(`/requests/randomId`)
.set("cookie", `${cookieName}=${superUserJwtToken}`)
.send(approvedExtensionRequest)
.end(function (err, res) {
Expand Down Expand Up @@ -779,7 +751,7 @@ describe("/requests Task", function () {
it("should return 401(Unauthorized) if user is not logged in", function (done) {
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.send(validTaskCreqtionRequest)
.end(function (err, res) {
expect(res).to.have.status(401);
Expand All @@ -793,7 +765,7 @@ describe("/requests Task", function () {
taskRequestObj.userId = userId1;
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(taskRequestObj)
.end(function (err, res) {
Expand All @@ -809,7 +781,7 @@ describe("/requests Task", function () {
delete taskRequestObj.taskId;
chai
.request(app)
.post("/requests?dev=true")
.post("/requests")
.set("cookie", `${cookieName}=${userJwtToken1}`)
.send(taskRequestObj)
.end(function (err, res) {
Expand Down
6 changes: 0 additions & 6 deletions test/unit/middlewares/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ describe("Create Request Validators", function () {
it("should pass validation for a valid create request", async function () {
req = {
body: validOooStatusRequests,
query: {
dev: "true",
},
};
res = {};
await createRequestsMiddleware(req as OooRequestCreateRequest, res as OooRequestResponse, nextSpy);
Expand All @@ -43,9 +40,6 @@ describe("Create Request Validators", function () {
it("should throw an error for an invalid create request", async function () {
req = {
body: invalidOooStatusRequests,
query: {
dev: "true",
},
};
res = {
boom: {
Expand Down
1 change: 0 additions & 1 deletion types/requests.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export type UpdateRequestBody = {
};

export type RequestQuery = {
dev?: string;
type?: string;
requestedBy?: string;
state?: REQUEST_STATE.APPROVED | REQUEST_STATE.PENDING | REQUEST_STATE.REJECTED;
Expand Down

0 comments on commit a6814b6

Please sign in to comment.