Skip to content

Commit

Permalink
fix: fix log in/log out helper functions
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalinDe committed Dec 5, 2023
1 parent a4b412d commit df1111e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unauthenticated
67 changes: 67 additions & 0 deletions web/frontend/tests/hars/personal_info.har
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"log": {
"version": "1.2",
"creator": {
"name": "Playwright",
"version": "1.40.1"
},
"browser": {
"name": "firefox",
"version": "119.0"
},
"entries": [
{
"startedDateTime": "2023-12-05T14:25:28.081Z",
"time": 0.06,
"request": {
"method": "GET",
"url": "http://127.0.0.1:3000/api/personal_info",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{ "name": "Host", "value": "127.0.0.1:3000" },
{ "name": "User-Agent", "value": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:119.0) Gecko/20100101 Firefox/119.0" },
{ "name": "Accept", "value": "*/*" },
{ "name": "Accept-Language", "value": "en-US" },
{ "name": "Accept-Encoding", "value": "gzip, deflate, br" },
{ "name": "Referer", "value": "http://127.0.0.1:3000/about" },
{ "name": "Connection", "value": "keep-alive" },
{ "name": "Sec-Fetch-Dest", "value": "empty" },
{ "name": "Sec-Fetch-Mode", "value": "cors" },
{ "name": "Sec-Fetch-Site", "value": "same-origin" }
],
"queryString": [],
"headersSize": -1,
"bodySize": -1
},
"response": {
"status": 401,
"statusText": "Unauthorized",
"httpVersion": "HTTP/1.1",
"cookies": [],
"headers": [
{ "name": "x-powered-by", "value": "Express" },
{ "name": "content-type", "value": "text/html; charset=utf-8" },
{ "name": "content-length", "value": "15" },
{ "name": "etag", "value": "W/\"f-n9L/T8H7FjcXU5+wSuxCD+6xHlo\"" },
{ "name": "set-cookie", "value": "connect.sid=s%3AO6aDExYv7Ocwz6IQUJ7l0I3u0XA7OHMg.Hq5%2FbR4nwsJbDjh1kVYuXweeFTmPF9d0Tx8t%2F1T3hOQ; Path=/; Expires=Wed, 06 Dec 2023 14:25:28 GMT; HttpOnly" },
{ "name": "date", "value": "Tue" },
{ "name": "date", "value": "05 Dec 2023 14:25:28 GMT" },
{ "name": "connection", "value": "keep-alive" },
{ "name": "keep-alive", "value": "timeout=5" }
],
"content": {
"size": -1,
"mimeType": "text/html; charset=utf-8",
"_file": "9fd2ff4fc1fb163717539fb04aec420feeb11e5a.html"
},
"headersSize": -1,
"bodySize": -1,
"redirectURL": ""
},
"cache": {},
"timings": { "send": -1, "wait": -1, "receive": 0.06 }
}
]
}
}
11 changes: 10 additions & 1 deletion web/frontend/tests/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export const SCIPER_ADMIN = '123456';
export const SCIPER_USER = '789012';

export async function mockPersonalInfo (page: any, admin = false) {
export async function mockPersonalInfo (page: any, authenticated = false, admin = false) {
if (!authenticated) {
await page.routeFromHAR(
'./tests/hars/personal_info.har',
{
url: `${process.env.FRONT_END_URL}/api/personal_info`,
update: false,
});
return;
}
await page.routeFromHAR(
`./tests/hars/personal_info.${admin ? SCIPER_ADMIN : SCIPER_USER}.har`,
{
Expand Down
2 changes: 2 additions & 0 deletions web/frontend/tests/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import {
assertOnlyVisibleToAuthenticated,
assertOnlyVisibleToAdmin,
} from './shared';
import { mockPersonalInfo } from './mocks';

initI18n();

test.beforeEach(async ({ page }) => {
await mockPersonalInfo(page);
await page.goto(`${process.env.FRONT_END_URL}/about`);
});

Expand Down
5 changes: 2 additions & 3 deletions web/frontend/tests/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ export function initI18n () {
}

export async function logIn (page: any, admin = false) {
await mockPersonalInfo(page, admin);
await mockPersonalInfo(page, true, admin);
await page.reload();
}

export async function logOut (page: any) {
await mockLogout(page);
await page.context().request.post(`${process.env.FRONT_END_URL}/api/logout`);
await mockPersonalInfo(page)
await page.reload();
}

Expand Down

0 comments on commit df1111e

Please sign in to comment.