From 2343767d089b17ad420c76c24bfb7e84c466841d Mon Sep 17 00:00:00 2001 From: Vitor Veras Date: Tue, 26 Jan 2021 12:10:12 -0300 Subject: [PATCH] refactor: rename LocalSaveAccessToken to LocalAccessTokenHandler --- .../local-save-access-token.spec.ts | 45 ------------------- .../local-save-access-token.ts | 9 ---- 2 files changed, 54 deletions(-) delete mode 100644 src/data/usecases/save-access-token/local-save-access-token.spec.ts delete mode 100644 src/data/usecases/save-access-token/local-save-access-token.ts diff --git a/src/data/usecases/save-access-token/local-save-access-token.spec.ts b/src/data/usecases/save-access-token/local-save-access-token.spec.ts deleted file mode 100644 index 9216ba4..0000000 --- a/src/data/usecases/save-access-token/local-save-access-token.spec.ts +++ /dev/null @@ -1,45 +0,0 @@ -import {StorageMock} from '@/data/test/mock-storage'; -import faker from 'faker'; -import {LocalSaveAccessToken} from './local-save-access-token'; - -type SutTypes = { - sut: LocalSaveAccessToken; - storageMock: StorageMock; -}; - -const makeSut = (): SutTypes => { - const storageMock = new StorageMock(); - const sut = new LocalSaveAccessToken(storageMock); - return { - sut, - storageMock, - }; -}; - -describe('LocalSaveAccessToken', () => { - test('Should call Storage with correct values on set', async () => { - const {sut, storageMock: storageMock} = makeSut(); - const fakeAccessToken = faker.random.uuid(); - await sut.save(fakeAccessToken); - expect(storageMock.key).toBe('accessToken'); - expect(storageMock.value).toBe(fakeAccessToken); - }); - test('Should return StorageSetError when failed to set information with AsyncStorage', () => { - // const {sut} = makeSut(); - // const storageObject = makeRandomData(); - // mockAsyncStorage.setItem = jest.fn((_key, _value) => { - // return Promise.reject(); - // }); - // const promise = sut.set(storageObject.key, storageObject.value); - // expect(promise).rejects.toThrow(new StorageSetError()); - }); - test('Should call AsyncStorage to retrieve information with correct values', async () => { - // const {sut} = makeSut(); - // const storageObject = makeRandomData(); - // await sut.get(storageObject.key); - // expect(AsyncStorage.getItem).toBeCalledWith(storageObject.key); - }); - test('Should return StorageGetError when failed to get information with AsyncStorage', () => {}); - test('Should call AsyncStorage to clear storage', () => {}); - test('Should return StorageClearError when failed to clear information with AsyncStorage', () => {}); -}); diff --git a/src/data/usecases/save-access-token/local-save-access-token.ts b/src/data/usecases/save-access-token/local-save-access-token.ts deleted file mode 100644 index 2962ad9..0000000 --- a/src/data/usecases/save-access-token/local-save-access-token.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {Storage} from '@/data/protocols/storage/storage'; -import {SaveAccessToken} from '@/domain/usecases'; - -export class LocalSaveAccessToken implements SaveAccessToken { - constructor(private readonly storage: Storage) {} - async save(accessToken: string): Promise { - await this.storage.set('accessToken', accessToken); - } -}