Skip to content

Commit

Permalink
feat(#26): ensure LoadAccountController call LoadAccount with correct…
Browse files Browse the repository at this point in the history
… value
  • Loading branch information
DanielAraldi committed Jul 29, 2023
1 parent 691e172 commit 9f329da
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/domain/usecases/load-account.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface LoadAccount {
load(accessToken: string): Promise<LoadAccount.Result>;
load(accountId: string): Promise<LoadAccount.Result>;
}

export namespace LoadAccount {
Expand Down
1 change: 1 addition & 0 deletions src/presentation/controllers/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './add-survey-controller';
export * from './edit-account-controller';
export * from './load-account-controller';
export * from './load-survey-result-controller';
export * from './load-surveys-controller';
export * from './login-controller';
Expand Down
17 changes: 17 additions & 0 deletions src/presentation/controllers/load-account-controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { LoadAccount } from '@/domain/usecases';
import { Controller, HttpResponse } from '@/presentation/protocols';

export class LoadAccountController implements Controller {
constructor(private readonly loadAccount: LoadAccount) {}

async handle(request: LoadAccountController.Request): Promise<HttpResponse> {
await this.loadAccount.load(request.accountId);
return null;
}
}

export namespace LoadAccountController {
export type Request = {
accountId: string;
};
}
12 changes: 12 additions & 0 deletions tests/presentation/mocks/mock-account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
AddAccount,
RefreshToken,
EditAccount,
LoadAccount,
} from '@/domain/usecases';
import { mockLoadAccountModel } from '@/tests/domain/mocks';
import { faker } from '@faker-js/faker';

export class AddAccountSpy implements AddAccount {
Expand Down Expand Up @@ -67,3 +69,13 @@ export class EditAccountSpy implements EditAccount {
return Promise.resolve(this.result);
}
}

export class LoadAccountSpy implements LoadAccount {
result = mockLoadAccountModel();
accountId: string;

async load(accountId: string): Promise<LoadAccount.Result> {
this.accountId = accountId;
return Promise.resolve(this.result);
}
}

0 comments on commit 9f329da

Please sign in to comment.