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

329 change endpoint offereditid to offeridedit #331

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
5,448 changes: 1,903 additions & 3,545 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"audit": "npm audit --production --audit-level=high"
},
"dependencies": {
"@babel/preset-env": "^7.13.15",
"@babel/preset-env": "^7.23.9",
"@date-io/date-fns": "^1.3.13",
"@hookform/resolvers": "^2.8.3",
"@material-ui/core": "^4.12.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const OfferDetails = ({

const { addField, addTech, addFieldWithUrl, addTechWithUrl, setLoadUrlFromFilters } = useChipsFieldSearch();

const history = useHistory();

const handleChipSetFields = useCallback((values) => {
if (isPage) {
history.push("/");
Expand All @@ -77,8 +79,6 @@ const OfferDetails = ({
}
}, [history, isPage, setLoadUrlFromFilters, addTech, addTechWithUrl]);

const history = useHistory();

const getHiddenOfferMessage = useCallback(() => {
if (visibilityState.isDisabled)
return getDisabledOfferMessage();
Expand Down
4 changes: 2 additions & 2 deletions src/components/Offers/Edit/EditOfferForm.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ describe("Edit Offer Form", () => {
applyURL,
} = offer;

expect(fetch).toHaveBeenCalledWith(expect.stringMatching(/.*\/offers\/edit\/test123/), expect.objectContaining({
expect(fetch).toHaveBeenCalledWith(expect.stringMatching(/.*\/offers\/test123\/edit/), expect.objectContaining({
body: JSON.stringify({
title,
jobMinDuration,
Expand Down Expand Up @@ -427,7 +427,7 @@ describe("Edit Offer Form", () => {
} = offer;


expect(fetch).toHaveBeenCalledWith(expect.stringMatching(/.*\/offers\/edit\/test123/), expect.objectContaining({
expect(fetch).toHaveBeenCalledWith(expect.stringMatching(/.*\/offers\/test123\/edit/), expect.objectContaining({
body: JSON.stringify({
title,
publishDate: new Date(newPublishDate.setHours(0, 0, 0, 0)).toISOString(),
Expand Down
3 changes: 1 addition & 2 deletions src/services/offerService.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ export const editOffer = measureTime(TIMED_ACTIONS.OFFER_EDIT, async ({
let isErrorRegistered = false;

try {
const res = await fetch(`${API_HOSTNAME}/offers/edit/${offerId}`, {
const res = await fetch(`${API_HOSTNAME}/offers/${offerId}/edit`, {
method: "POST",
headers: {
"Content-Type": "application/json",
Expand All @@ -355,7 +355,6 @@ export const editOffer = measureTime(TIMED_ACTIONS.OFFER_EDIT, async ({
body: JSON.stringify(data),
});
const json = await res.json();

if (!res.ok) {
createErrorEvent(
OFFER_EDIT_METRIC_ID,
Expand Down
32 changes: 31 additions & 1 deletion src/services/offerService.spec.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import config from "../config";

import { hideOffer, disableOffer, enableOffer } from "./offerService";
import { hideOffer, disableOffer, enableOffer, editOffer } from "./offerService";
import Constants from "../utils/Constants";
const { API_HOSTNAME } = config;

describe("Offer Service", () => {

const id = "60f16140fb2b9800321e2ca1";
const adminReason = "This offer is offensive.";
const data = { };

beforeEach(() => {
fetch.resetMocks();
Expand Down Expand Up @@ -56,6 +57,23 @@ describe("Offer Service", () => {
});
});

it("Should send a POST request to edit a specific offer", async () => {

// Simulate request success
fetch.mockResponse(JSON.stringify({ mockData: true }));

await editOffer({ offerId: id }, data);

expect(fetch).toHaveBeenCalledWith(`${API_HOSTNAME}/offers/${id}/edit`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
credentials: "include",
body: JSON.stringify(data),
});
});

it("Should handle non successful requests", async () => {
const errors = [{ msg: "error1" }, { msg: "error2" }];

Expand All @@ -79,6 +97,12 @@ describe("Offer Service", () => {
} catch (e) {
expect(e).toStrictEqual(errors);
}

try {
await editOffer(id);
} catch (e) {
expect(e).toStrictEqual(errors);
}
});

it("Should handle network error", async () => {
Expand All @@ -103,5 +127,11 @@ describe("Offer Service", () => {
} catch (e) {
expect(e).toStrictEqual([{ msg: Constants.UNEXPECTED_ERROR_MESSAGE }]);
}

try {
await editOffer(id);
} catch (e) {
expect(e).toStrictEqual([{ msg: Constants.UNEXPECTED_ERROR_MESSAGE }]);
}
});
});
Loading