-
-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add option to transition your data - internal feature
- Loading branch information
1 parent
e41f239
commit 3635e17
Showing
13 changed files
with
249 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
packages/services/src/Domain/InternalFeatures/InternalFeature.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export enum InternalFeature { | ||
Vaults = 'vaults', | ||
HomeServer = 'home-server', | ||
Transition = 'transition', | ||
} |
34 changes: 34 additions & 0 deletions
34
...es/services/src/Domain/UseCase/Transition/GetTransitionStatus/GetTransitionStatus.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { HttpServiceInterface } from '@standardnotes/api' | ||
|
||
import { GetTransitionStatus } from './GetTransitionStatus' | ||
|
||
describe('GetTransitionStatus', () => { | ||
let httpService: HttpServiceInterface | ||
|
||
const createUseCase = () => new GetTransitionStatus(httpService) | ||
|
||
beforeEach(() => { | ||
httpService = { | ||
get: jest.fn(), | ||
} as unknown as HttpServiceInterface | ||
}) | ||
|
||
it('should get transition status', async () => { | ||
const useCase = createUseCase() | ||
;(httpService.get as jest.Mock).mockResolvedValueOnce({ status: 200, data: { status: 'TO-DO' } }) | ||
|
||
const result = await useCase.execute() | ||
|
||
expect(result.isFailed()).toBe(false) | ||
expect(result.getValue).toBe('TO-DO') | ||
}) | ||
|
||
it('should fail to get transition status', async () => { | ||
const useCase = createUseCase() | ||
;(httpService.get as jest.Mock).mockResolvedValueOnce({ status: 400 }) | ||
|
||
const result = await useCase.execute() | ||
|
||
expect(result.isFailed()).toBe(true) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
packages/services/src/Domain/UseCase/Transition/GetTransitionStatus/GetTransitionStatus.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Result, UseCaseInterface } from '@standardnotes/domain-core' | ||
import { HttpServiceInterface } from '@standardnotes/api' | ||
import { HttpStatusCode } from '@standardnotes/responses' | ||
|
||
export class GetTransitionStatus implements UseCaseInterface<'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED'> { | ||
constructor(private httpService: HttpServiceInterface) {} | ||
|
||
async execute(): Promise<Result<'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED'>> { | ||
const response = await this.httpService.get('/v1/users/transition-status') | ||
|
||
if (response.status !== HttpStatusCode.Success) { | ||
return Result.fail('Failed to get transition status') | ||
} | ||
|
||
return Result.ok((response.data as { status: 'TO-DO' | 'STARTED' | 'FINISHED' | 'FAILED' }).status) | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
packages/services/src/Domain/UseCase/Transition/StartTransition/StartTransition.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { HttpServiceInterface } from '@standardnotes/api' | ||
|
||
import { StartTransition } from './StartTransition' | ||
|
||
describe('StartTransition', () => { | ||
let httpService: HttpServiceInterface | ||
|
||
const createUseCase = () => new StartTransition(httpService) | ||
|
||
beforeEach(() => { | ||
httpService = { | ||
post: jest.fn(), | ||
} as unknown as HttpServiceInterface | ||
}) | ||
|
||
it('should start transition', async () => { | ||
const useCase = createUseCase() | ||
;(httpService.post as jest.Mock).mockResolvedValueOnce({ status: 200 }) | ||
|
||
const result = await useCase.execute() | ||
|
||
expect(result.isFailed()).toBe(false) | ||
}) | ||
|
||
it('should fail to start transition', async () => { | ||
const useCase = createUseCase() | ||
;(httpService.post as jest.Mock).mockResolvedValueOnce({ status: 400 }) | ||
|
||
const result = await useCase.execute() | ||
|
||
expect(result.isFailed()).toBe(true) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
packages/services/src/Domain/UseCase/Transition/StartTransition/StartTransition.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { HttpServiceInterface } from '@standardnotes/api' | ||
import { Result, UseCaseInterface } from '@standardnotes/domain-core' | ||
import { HttpStatusCode } from '@standardnotes/responses' | ||
|
||
export class StartTransition implements UseCaseInterface<void> { | ||
constructor(private httpService: HttpServiceInterface) {} | ||
|
||
async execute(): Promise<Result<void>> { | ||
const response = await this.httpService.post('/v1/items/transition') | ||
|
||
if (response.status !== HttpStatusCode.Success) { | ||
return Result.fail('Failed to start transition') | ||
} | ||
|
||
return Result.ok() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters