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

Add role name to profile page, replace GET route handlers with functions in server components #84

Open
wants to merge 6 commits into
base: main
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
21 changes: 21 additions & 0 deletions galasa-ui/extendedJsdomEnvironment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright contributors to the Galasa project
*
* SPDX-License-Identifier: EPL-2.0
*/
import JSDOMEnvironment from 'jest-environment-jsdom';

/**
* An extension of the JSDOM environment created to fix issues with resolving
* global functions in unit tests.
*/
export default class ExtendedJSDOMEnvironment extends JSDOMEnvironment {
constructor(...args: ConstructorParameters<typeof JSDOMEnvironment>) {
super(...args);

// structuredClone() was added in Node 17 but a "ReferenceError: structuredClone is not defined"
// error is thrown when running tests - see https://github.com/jsdom/jsdom/issues/3363
// This line forces the unit tests to use the correct implementation of structuredClone()
this.global.structuredClone = structuredClone;
}
}
2 changes: 1 addition & 1 deletion galasa-ui/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const createJestConfig = nextJest({
// The Jest configuration to use in this project - see https://jestjs.io/docs/configuration for more information
const config = {
setupFilesAfterEnv: ["<rootDir>/setupTests.ts"],
testEnvironment: "jest-environment-jsdom",
testEnvironment: "./extendedJsdomEnvironment.ts",

// Ignore auto-generated code in coverage reports
coveragePathIgnorePatterns: [
Expand Down
111 changes: 62 additions & 49 deletions galasa-ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 1 addition & 25 deletions galasa-ui/src/app/auth/tokens/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import { createAuthenticatedApiConfiguration } from '@/utils/api';
import AuthCookies from '@/utils/authCookies';
import { cookies } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server';
import { AuthenticationAPIApi, UsersAPIApi } from '@/generated/galasaapi';
import * as Constants from "@/utils/constants";
import { AuthenticationAPIApi } from '@/generated/galasaapi';

// Stop this route from being pre-rendered
export const dynamic = 'force-dynamic';
Expand Down Expand Up @@ -48,29 +47,6 @@ export async function POST(request: NextRequest) {
}
}

export async function GET(request: NextRequest) {
// Call out to the API server's /auth/tokens endpoint to retrieve all tokens for a user

const authApiClientWithAuthHeader = new AuthenticationAPIApi(createAuthenticatedApiConfiguration());
const userApiClientWithAuthHeader = new UsersAPIApi(createAuthenticatedApiConfiguration());

const response = await userApiClientWithAuthHeader.getUserByLoginId(Constants.CLIENT_API_VERSION,"me");

const loginId = response.length > 0 && response[0].loginId;

if (loginId) {

const tokens = await authApiClientWithAuthHeader.getTokens(Constants.CLIENT_API_VERSION, loginId);

const serializedTokens = JSON.stringify(tokens.tokens);
return (new NextResponse(serializedTokens, {status: 200}));

} else {
return (new NextResponse("No login ID provided", {status : 400}));
}

}

export async function DELETE(request: NextRequest){

const { tokenId } = await request.json();
Expand Down
26 changes: 0 additions & 26 deletions galasa-ui/src/app/home/route.ts

This file was deleted.

4 changes: 2 additions & 2 deletions galasa-ui/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* SPDX-License-Identifier: EPL-2.0
*/

import PageHeader from '@/components/PageHeader';
import '../styles/global.scss';
import PageHeader from '@/components/headers/PageHeader';
import '@/styles/global.scss';

export const dynamic = "force-dynamic";

Expand Down
Loading
Loading