diff --git a/src/api/middleware/validators/offer.js b/src/api/middleware/validators/offer.js index 40e9f4a60..d6cc476f7 100644 --- a/src/api/middleware/validators/offer.js +++ b/src/api/middleware/validators/offer.js @@ -12,8 +12,6 @@ import OfferConstants from "../../../models/constants/Offer.js"; import Company from "../../../models/Company.js"; import Offer, { validatePublishEndDateLimit } from "../../../models/Offer.js"; import { - HOUR_IN_MS, - OFFER_EDIT_GRACE_PERIOD_HOURS, MONTH_IN_MS, OFFER_MAX_LIFETIME_MONTHS } from "../../../models/constants/TimeConstants.js"; @@ -430,17 +428,8 @@ export const isEditable = async (req, res, next) => { const offer = await Offer.findById(req.params.offerId); const currentDate = new Date(Date.now()); - // Verify if offer editing grace period is over - const timeDiff = currentDate - offer.createdAt; - const diffInHours = timeDiff / HOUR_IN_MS; - if (offer.publishEndDate.toISOString() <= currentDate.toISOString()) { return next(new APIError(HTTPStatus.FORBIDDEN, ErrorTypes.FORBIDDEN, ValidationReasons.OFFER_EXPIRED(req.params.offerId))); - } else if (offer.publishDate.toISOString() <= currentDate.toISOString() && diffInHours > OFFER_EDIT_GRACE_PERIOD_HOURS) { - return next( - new APIError(HTTPStatus.FORBIDDEN, ErrorTypes.FORBIDDEN, ValidationReasons.OFFER_EDIT_PERIOD_OVER(diffInHours.toFixed(2))) - ); - } return next(); diff --git a/src/models/constants/TimeConstants.js b/src/models/constants/TimeConstants.js index a30115136..49455dccb 100644 --- a/src/models/constants/TimeConstants.js +++ b/src/models/constants/TimeConstants.js @@ -1,4 +1,3 @@ export const MONTH_IN_MS = 1000 * 3600 * 24 * 30.42; export const HOUR_IN_MS = 1000 * 3600; export const OFFER_MAX_LIFETIME_MONTHS = 6; -export const OFFER_EDIT_GRACE_PERIOD_HOURS = 1; diff --git a/test/end-to-end/offer.js b/test/end-to-end/offer.js index 0a43360bd..875a7e460 100644 --- a/test/end-to-end/offer.js +++ b/test/end-to-end/offer.js @@ -15,8 +15,6 @@ import ValidationReasons from "../../src/api/middleware/validators/validationRea import { Types } from "mongoose"; import CompanyConstants from "../../src/models/constants/Company"; import { - OFFER_EDIT_GRACE_PERIOD_HOURS, - HOUR_IN_MS, MONTH_IN_MS, OFFER_MAX_LIFETIME_MONTHS } from "../../src/models/constants/TimeConstants"; @@ -1840,8 +1838,6 @@ describe("Offer endpoint tests", () => { describe("POST /offers/edit/:offerId", () => { let createOffer, expired_test_offer, - grace_period_over_test_offer, - grace_period_valid_test_offer, future_test_offer, valid_test_offer_1, valid_test_offer_2, @@ -1874,18 +1870,6 @@ describe("Offer endpoint tests", () => { "publishEndDate": "2019-11-18" })); - grace_period_over_test_offer = await createOffer(generateTestOffer({ - "publishDate": (new Date(Date.now())).toISOString(), - "publishEndDate": (new Date(Date.now() + (2 * DAY_TO_MS))).toISOString() - } - )); - - grace_period_valid_test_offer = await createOffer(generateTestOffer({ - "publishDate": (new Date(Date.now())).toISOString(), - "publishEndDate": (new Date(Date.now() + (2 * DAY_TO_MS))).toISOString() - } - )); - future_test_offer = await createOffer(generateTestOffer({ "publishDate": (new Date(Date.now() + (2 * DAY_TO_MS))).toISOString(), "publishEndDate": (new Date(Date.now() + (3 * DAY_TO_MS))).toISOString(), @@ -1957,39 +1941,6 @@ describe("Offer endpoint tests", () => { expect(res.body.errors).toContainEqual({ msg: ValidationReasons.OFFER_EXPIRED(expired_test_offer._id.toString()) }); }); - describe("should fail if offer with grace period over", () => { - const RealDateNow = Date.now; - const mockDate = new Date(Date.now() + (OFFER_EDIT_GRACE_PERIOD_HOURS * HOUR_IN_MS * 2)); - beforeEach(() => { - Date.now = () => mockDate.getTime(); - }); - - afterEach(() => { - Date.now = RealDateNow; - }); - - test("should fail offer with grace period over", async () => { - const expired_over_hours = - ((new Date(Date.now())).getTime() - (new Date(grace_period_over_test_offer.createdAt)).getTime()) / HOUR_IN_MS; - const res = await test_agent - .post(`/offers/edit/${grace_period_over_test_offer._id.toString()}`) - .send(withGodToken()) - .expect(HTTPStatus.FORBIDDEN); - expect(res.body).toHaveProperty("errors"); - expect(res.body.errors).toContainEqual({ - msg: ValidationReasons.OFFER_EDIT_PERIOD_OVER(expired_over_hours.toFixed(2)) - }); - }); - - }); - - test("should allow editing offer with valid grace period", async () => { - await test_agent - .post(`/offers/edit/${grace_period_valid_test_offer._id.toString()}`) - .send(withGodToken()) - .expect(HTTPStatus.OK); - }); - test("should allow editing offer in the future", async () => { await test_agent .post(`/offers/edit/${future_test_offer._id.toString()}`)