Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to fetch onboarding extension request #2331

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion middlewares/validators/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const getRequestsMiddleware = async (req: OooRequestCreateRequest, res: O
id: joi.string().optional(),
type: joi
.string()
.valid(REQUEST_TYPE.OOO, REQUEST_TYPE.EXTENSION, REQUEST_TYPE.TASK, REQUEST_TYPE.ALL)
.valid(REQUEST_TYPE.OOO, REQUEST_TYPE.EXTENSION, REQUEST_TYPE.TASK, REQUEST_TYPE.ALL, REQUEST_TYPE.ONBOARDING)
.optional(),
requestedBy: joi.string().insensitive().optional(),
state: joi
Expand Down
2 changes: 1 addition & 1 deletion models/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export const getRequests = async (query: any) => {

if (requestedBy) {
const requestedByUserId = await getUserId(requestedBy);
requestQuery = requestQuery.where("requestedBy", "==", requestedByUserId);
requestQuery = requestQuery.where("requestedBy", "in", [requestedByUserId, requestedBy]);
}
if (type) {
requestQuery = requestQuery.where("type", "==", type);
Expand Down
96 changes: 96 additions & 0 deletions test/integration/onboardingExtension.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import chai, { expect } from "chai";
import chaiHttp from "chai-http";
import app from "../../app";
import cleanDb from "../utils/cleanDb";
import * as requestQuery from "../../models/requests";
import { REQUEST_FETCHED_SUCCESSFULLY, REQUEST_STATE, REQUEST_TYPE } from "../../constants/requests";
import addUser from "../utils/addUser";
import userDataFixture from "../fixtures/user/user";
const usersData = userDataFixture();

chai.use(chaiHttp);

describe("/requests Onboarding Extension", () => {
describe("GET /requests",() => {
const getEndpoint = "/requests";
const username = usersData[4].username;

beforeEach(async () => {
await addUser(usersData[4]);
});

afterEach(async () => {
await cleanDb();
});

it("should return 204 content when onboarding extension request does not exist", (done) => {
requestQuery.createRequest({ type: REQUEST_TYPE.OOO });
chai
.request(app)
.get(`${getEndpoint}?type=ONBOARDING`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(204);
return done();
});
});

it("should fetch onboarding extension request by requestedBy field", (done) => {
requestQuery.createRequest({ type: REQUEST_TYPE.ONBOARDING, requestedBy: username });
chai
.request(app)
.get(`${getEndpoint}?requestedBy=${username}&type=ONBOARDING`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(200);
expect(res.body.message).to.equal(REQUEST_FETCHED_SUCCESSFULLY);
expect(res.body.data[0].type).to.equal(REQUEST_TYPE.ONBOARDING);
expect(res.body.data[0].requestedBy).to.equal(username);
return done();
});
});

it("shopuld return 204 response when onboarding extension request does not exist for a user", (done) => {
requestQuery.createRequest({ type: REQUEST_TYPE.OOO, requestedBy: username });
chai
.request(app)
.get(`${getEndpoint}?requestedBy=${username}&type=ONBOARDING`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(204);
return done();
});
});

it("should fetch onboarding extension request by type field", (done) => {
requestQuery.createRequest({ type: REQUEST_TYPE.ONBOARDING });
chai
.request(app)
.get(`${getEndpoint}?type=ONBOARDING`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(200);
expect(res.body.message).to.equal(REQUEST_FETCHED_SUCCESSFULLY);
expect(res.body.data.length).to.equal(1);
expect(res.body.data[0].type).to.equal("ONBOARDING");
return done();
});
});

it("should fetch onboarding extension request by state field", (done) => {
requestQuery.createRequest({ type: REQUEST_TYPE.ONBOARDING, state: REQUEST_STATE.APPROVED });
chai
.request(app)
.get(`${getEndpoint}?state=APPROVED`)
.end((err, res) => {
if (err) return done(err);
expect(res.statusCode).to.equal(200);
expect(res.body.message).to.equal(REQUEST_FETCHED_SUCCESSFULLY);
expect(res.body.data.length).to.equal(1);
expect(res.body.data[0].type).to.equal("ONBOARDING");
expect(res.body.data[0].state).to.equal("APPROVED");
return done();
});
});
});
});
2 changes: 1 addition & 1 deletion test/integration/requests.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ describe("/requests OOO", function () {
.end(function (err, res) {
expect(res).to.have.status(400);
expect(res.body.error).to.equal("Bad Request");
expect(res.body.message).to.equal('"type" must be one of [OOO, EXTENSION, TASK, ALL]');
expect(res.body.message).to.equal('"type" must be one of [OOO, EXTENSION, TASK, ALL, ONBOARDING]');
done();
});
});
Expand Down
Loading