Getting login token

This commit is contained in:
Kira 2023-09-18 09:45:32 -07:00
parent f29f0c980b
commit 8edcdd925d
3 changed files with 6 additions and 4 deletions

View File

@ -3,9 +3,12 @@ import * as nodeFetch from "node-fetch"
export const getLoginToken = async () => { export const getLoginToken = async () => {
const response = await nodeFetch("http://localhost:2221/api/login", { const response = await nodeFetch("http://localhost:2221/api/login", {
method: "POST", method: "POST",
body: { "username": "admin", "password":"Admin123" } body: JSON.stringify({ "username": "admin", "password":"Admin123" })
}) })
if(response.status !== 200) {
throw new Error("An error occured trying to retrieve the login token.")
}
const body = await response.json() const body = await response.json()
return body.token return body.token
} }

View File

@ -5,6 +5,5 @@ export class MyAccountPage {
visit = async () => { visit = async () => {
await this.page.goto("/my-account") await this.page.goto("/my-account")
await this.page.pause()
} }
} }

View File

@ -5,8 +5,8 @@ import { getLoginToken } from "../api-calls/getLoginToken.js"
test.only("My Account using cookie injection", async ({page}) => { test.only("My Account using cookie injection", async ({page}) => {
//const loginToken = await getLoginToken() const loginToken = await getLoginToken()
//console.warn({loginToken}) console.warn({loginToken})
const myAccount = new MyAccountPage(page) const myAccount = new MyAccountPage(page)
await myAccount.visit() await myAccount.visit()