Skip to content

Commit

Permalink
revert: router di to OAuthLoginUseCase
Browse files Browse the repository at this point in the history
  • Loading branch information
frascuchon committed Oct 28, 2024
1 parent a0e4017 commit b8ddd03
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 33 deletions.
2 changes: 1 addition & 1 deletion argilla-frontend/v1/di/di.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export const loadDependencyContainer = (context: Context) => {
register(LoadUserUseCase).withDependencies(useAuth, UserRepository).build(),

register(OAuthLoginUseCase)
.withDependencies(useAuth, OAuthRepository, LoadUserUseCase, useRoutes)
.withDependencies(useAuth, OAuthRepository, LoadUserUseCase)
.build(),

register(AuthLoginUseCase)
Expand Down
18 changes: 1 addition & 17 deletions argilla-frontend/v1/domain/usecases/oauth-login-use-case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import {
import { IAuthService } from "../services/IAuthService";
import { IOAuthRepository } from "../services/IOAuthRepository";
import { LoadUserUseCase } from "./load-user-use-case";
import { RouterService } from "~/v1/domain/services/RouterService";

export class OAuthLoginUseCase {
constructor(
private readonly auth: IAuthService,
private readonly oauthRepository: IOAuthRepository,
private readonly loadUser: LoadUserUseCase,
private readonly router: RouterService
private readonly loadUser: LoadUserUseCase
) {}

async getProviders(): Promise<OAuthProvider[]> {
Expand All @@ -28,18 +26,6 @@ export class OAuthLoginUseCase {
return this.oauthRepository.authorize(provider);
}

redirect() {
let { redirect } = this.router.getQuery();
if (Array.isArray(redirect)) {
redirect = redirect[0];
}

this.router.go(redirect || "/", {
external: false,
newWindow: false,
});
}

async login(provider: ProviderType, oauthParams: OAuthParams) {
await this.auth.logout();

Expand All @@ -49,8 +35,6 @@ export class OAuthLoginUseCase {
await this.auth.setUserToken(token);

await this.loadUser.execute();

this.redirect();
}
}
}
19 changes: 4 additions & 15 deletions argilla-frontend/v1/domain/usecases/oauth-login-usecase.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import { mock } from "@codescouts/test/jest";
import { IOAuthRepository } from "../services/IOAuthRepository";
import { IAuthService } from "../services/IAuthService";
import { RouterService } from "../services/RouterService";
import { IUserRepository } from "../services/IUserRepository";
import { OAuthLoginUseCase } from "./oauth-login-use-case";
import { LoadUserUseCase } from "./load-user-use-case";

describe("OAuthLoginUseCase should", () => {
test("logout user before call the login on backend", async () => {
const auth = mock<IAuthService>();
const router = mock<RouterService>();
const oauthRepository = mock<IOAuthRepository>();
const loadUserUseCase = new LoadUserUseCase(auth, mock<IUserRepository>());

Expand All @@ -18,8 +16,7 @@ describe("OAuthLoginUseCase should", () => {
const useCase = new OAuthLoginUseCase(
auth,
oauthRepository,
loadUserUseCase,
router
loadUserUseCase
);

try {
Expand All @@ -31,16 +28,14 @@ describe("OAuthLoginUseCase should", () => {

test("call the backend after logout", async () => {
const auth = mock<IAuthService>();
const router = mock<RouterService>();

const oauthRepository = mock<IOAuthRepository>();
const loadUserUseCase = new LoadUserUseCase(auth, mock<IUserRepository>());

const useCase = new OAuthLoginUseCase(
auth,
oauthRepository,
loadUserUseCase,
router
loadUserUseCase
);

await useCase.login("huggingface", null);
Expand All @@ -50,19 +45,15 @@ describe("OAuthLoginUseCase should", () => {

test("save token if the token is defined", async () => {
const auth = mock<IAuthService>();
const router = mock<RouterService>();
const oauthRepository = mock<IOAuthRepository>();
const loadUserUseCase = new LoadUserUseCase(auth, mock<IUserRepository>());

router.getQuery.mockReturnValue({});

oauthRepository.login.mockResolvedValue("FAKE_TOKEN");

const useCase = new OAuthLoginUseCase(
auth,
oauthRepository,
loadUserUseCase,
router
loadUserUseCase
);

await useCase.login("huggingface", null);
Expand All @@ -72,7 +63,6 @@ describe("OAuthLoginUseCase should", () => {

test("no save token if the token is not defined", async () => {
const auth = mock<IAuthService>();
const router = mock<RouterService>();
const oauthRepository = mock<IOAuthRepository>();
const loadUserUseCase = new LoadUserUseCase(auth, mock<IUserRepository>());

Expand All @@ -81,8 +71,7 @@ describe("OAuthLoginUseCase should", () => {
const useCase = new OAuthLoginUseCase(
auth,
oauthRepository,
loadUserUseCase,
router
loadUserUseCase
);

await useCase.login("huggingface", null);
Expand Down

0 comments on commit b8ddd03

Please sign in to comment.