Skip to content
This repository was archived by the owner on Apr 12, 2023. It is now read-only.

Commit ea5ca12

Browse files
committed
Endringer i API + test
1 parent 530f018 commit ea5ca12

File tree

16 files changed

+249
-251
lines changed

16 files changed

+249
-251
lines changed

__tests__/index.test.jsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { render, screen } from "@testing-library/react";
1+
import { act, render, screen, waitFor } from "@testing-library/react";
22
import Home from "../src/pages/index";
33
import "@testing-library/jest-dom";
44
import fetchMock from "jest-fetch-mock";
@@ -27,15 +27,19 @@ describe("Home", () => {
2727
fetch.resetMocks();
2828
});
2929

30-
it("renders a heading", () => {
31-
// fetch.mockResponseOnce(JSON.stringify([]));
30+
it("renders a heading", async () => {
31+
fetch.mockResponseOnce(JSON.stringify([]));
3232

33-
render(<Home periods={[]} />);
34-
35-
const heading = screen.getByRole("heading", {
36-
name: /Ny løsning/i,
33+
act(() => {
34+
render(<Home periods={[]} />);
3735
});
3836

39-
expect(heading).toBeInTheDocument();
37+
await waitFor(() => {
38+
const heading = screen.getByRole("heading", {
39+
name: /Ny løsning/i,
40+
});
41+
42+
expect(heading).toBeInTheDocument();
43+
});
4044
});
4145
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.loader {
22
display: flex;
33
justify-content: center;
4+
margin: 15rem;
45
}

src/models/LoadedMeldeperiode.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export type LoadedMeldeperiode = {
2+
meldeperiodeId: number;
3+
fomDato: string;
4+
tomDato: string;
5+
frist: string;
6+
}

src/pages/api/period/get.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

src/pages/api/period/save.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/pages/api/period/send.ts

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/pages/api/periods/[id].ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
import { doRequest } from "../../../utils/api.utils";
3+
4+
export default async function handler(
5+
req: NextApiRequest,
6+
res: NextApiResponse
7+
) {
8+
try {
9+
const { id } = req.query
10+
const url = `${process.env.DP_RAPP_API_URL}/api/v1/mellomlagring/hente/${id}`;
11+
12+
const response = await doRequest(req, res, "GET", url);
13+
14+
if (!response.ok) {
15+
return res.status(500).send(`Unexpected response status: ${response.statusText}`)
16+
}
17+
18+
const json = await response.json();
19+
20+
return res.json(json);
21+
} catch (error) {
22+
return res.status(500).send(error);
23+
}
24+
}

src/pages/api/periods/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
import { doRequest } from "../../../utils/api.utils";
3+
4+
export default async function handler(
5+
req: NextApiRequest,
6+
res: NextApiResponse
7+
) {
8+
try {
9+
const url = `${process.env.DP_RAPP_API_URL}/api/v1/meldeperiode/hente`;
10+
11+
const response = await doRequest(req, res, "GET", url);
12+
13+
if (!response.ok) {
14+
return res.status(500).send(`Unexpected response status: ${response.statusText}`)
15+
}
16+
17+
const json = await response.json();
18+
19+
return res.json(json);
20+
} catch (error) {
21+
return res.status(500).send(error);
22+
}
23+
}

src/pages/api/periods/save.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
import { doRequest } from "../../../utils/api.utils";
3+
4+
export default async function handler(
5+
req: NextApiRequest,
6+
res: NextApiResponse
7+
) {
8+
try {
9+
const url = `${process.env.DP_RAPP_API_URL}/api/v1/mellomlagring/lagre`;
10+
11+
const response = await doRequest(req, res, "POST", url);
12+
13+
if (!response.ok) {
14+
return res.status(500).send(`Unexpected response status: ${response.statusText}`)
15+
}
16+
17+
return res.end()
18+
} catch (error) {
19+
return res.status(500).send(error);
20+
}
21+
}

src/pages/api/periods/send.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { NextApiRequest, NextApiResponse } from "next";
2+
import { doRequest } from "../../../utils/api.utils";
3+
4+
export default async function handler(
5+
req: NextApiRequest,
6+
res: NextApiResponse
7+
) {
8+
try {
9+
const url = `${process.env.DP_RAPP_API_URL}/api/v1/send`;
10+
11+
const response = await doRequest(req, res, "POST", url);
12+
13+
if (!response.ok) {
14+
return res.status(500).send(`Unexpected response status: ${response.statusText}`)
15+
}
16+
17+
return res.end();
18+
} catch (error) {
19+
return res.status(500).send(error);
20+
}
21+
}

0 commit comments

Comments
 (0)