Skip to content

Commit

Permalink
sdk: fix tests and endpoints for login config feature rucio#171
Browse files Browse the repository at this point in the history
  • Loading branch information
maany committed Jun 21, 2023
1 parent 2e42040 commit f1a262c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 41 deletions.
32 changes: 0 additions & 32 deletions src/lib/infrastructure/ioc/ioc-symbols-input-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,3 @@ const INPUT_PORT = {
}

export default INPUT_PORT;

// import fs from 'fs';
// import path from 'path';


// // Scan the ports directory for files
// const portFiles = fs.readdirSync(path.join(__dirname, '../../core/port/primary'));

// interface InputPort {
// [key: string]: symbol;
// }

// const INPUT_PORT: InputPort = {};


// const getInputPorts = () => {
// // console.log(`Registering input ports...${portFiles.length} found`)
// // for (const file of portFiles) {
// // let refName = ''
// // if (file.includes('-ports.ts')) {
// // refName = file.replace('-ports.ts', '').replaceAll('-', '_').toUpperCase();
// // } else if (file.includes('-port.ts')) {
// // refName = file.replace('-input-port.ts', '').replaceAll('-', '_').toUpperCase();
// // }
// // const symbolName = `${refName}_INPUT_PORT`;

// // INPUT_PORT[refName] = Symbol.for(symbolName);
// // console.log(`Registered ${symbolName}`)
// // }
// // return INPUT_PORT;
// }
// export { INPUT_PORT, getInputPorts };
3 changes: 1 addition & 2 deletions src/lib/sdk/ioc-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ TControllerParams extends TParameters,
(response: NextApiResponse) => {
const presenter = new Presenter(response);
return new UseCase(presenter, ...useCaseContructorArgs);
}
);
});
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/pages/api/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { NextApiRequest, NextApiResponse } from "next"
import { withSessionRoute } from "@/lib/infrastructure/auth/session-utils"
import appContainer from "@/lib/infrastructure/ioc/container-config"
import CONTROLLERS from "@/lib/infrastructure/ioc/ioc-symbols-controllers"
import { ILoginConfigController } from "@/lib/infrastructure/controller/login-config-controller"
import { BaseController } from "@/lib/sdk/controller"
import LoginConfigController, { LoginConfigControllerParams } from "@/lib/infrastructure/controller/login-config-controller"

async function loginRoute(req: NextApiRequest, res: NextApiResponse) {
const sessionExists = req.session !== undefined
Expand All @@ -25,8 +26,11 @@ async function loginRoute(req: NextApiRequest, res: NextApiResponse) {
res.redirect(`/auth/login?callbackUrl=${callbackUrl}`)
}
else if (req.method === 'POST') {
const loginConfigController = appContainer.get<ILoginConfigController>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.getLoginViewModel(req.session, res)
const loginConfigController: LoginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.execute({
session: req.session,
response: res
})
}
else {
res.status(405).json({ error: 'Method not allowed' })
Expand Down
14 changes: 10 additions & 4 deletions test/api/auth/login-page-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,11 @@ describe('Login Page Config API Test', () => {
process.env['VO_VO2_NAME'] = 'vo2'


const loginConfigController = appContainer.get<ILoginConfigController>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.getLoginViewModel(session, res);
const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.execute({
session: session,
response: res as any,
});

expect(res._getStatusCode()).toBe(200);
const viewModel: LoginViewModel = JSON.parse(res._getData());
Expand Down Expand Up @@ -133,8 +136,11 @@ describe('Login Page Config API Test', () => {

delete process.env['OIDC_PROVIDERS']

const loginConfigController = appContainer.get<ILoginConfigController>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.getLoginViewModel(session, res);
const loginConfigController = appContainer.get<BaseController<LoginConfigControllerParams, void>>(CONTROLLERS.LOGIN_CONFIG)
await loginConfigController.execute({
session: session,
response: res as any,
});

expect(res._getStatusCode()).toBe(500);
const viewModel: LoginViewModel = JSON.parse(res._getData());
Expand Down

0 comments on commit f1a262c

Please sign in to comment.