-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from autentia/fix/181789531-prevent-remove-ima…
…ge-updating fix: 181789531 prevent remove image updating
- Loading branch information
Showing
7 changed files
with
86 additions
and
76 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
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
31 changes: 31 additions & 0 deletions
31
src/modules/binnacle/data-access/actions/get-activity-image-action.test.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,31 @@ | ||
import { ActivitiesRepository } from 'modules/binnacle/data-access/repositories/activities-repository' | ||
import { mock } from 'jest-mock-extended' | ||
import { GetActivityImageAction } from './get-activity-image-action' | ||
import { ActivityFormState } from '../state/activity-form-state' | ||
|
||
describe('GetActivityImageAction', () => { | ||
it('should get the activity image', async () => { | ||
const { getActivityImageAction, activitiesRepository, activityFormState, expectedValue } = | ||
setup() | ||
await getActivityImageAction.execute(1) | ||
|
||
expect(activitiesRepository.getActivityImage).toHaveBeenCalledWith(1) | ||
expect(activityFormState.initialImageFile).toBe(expectedValue) | ||
}) | ||
}) | ||
|
||
function setup() { | ||
const activitiesRepository = mock<ActivitiesRepository>() | ||
|
||
const activityFormState = new ActivityFormState() | ||
|
||
const expectedValue = 'image' | ||
activitiesRepository.getActivityImage.mockResolvedValue(expectedValue) | ||
|
||
return { | ||
getActivityImageAction: new GetActivityImageAction(activitiesRepository, activityFormState), | ||
activitiesRepository, | ||
activityFormState, | ||
expectedValue | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/modules/binnacle/data-access/actions/get-activity-image-action.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,26 @@ | ||
import { ActivitiesRepository } from '../repositories/activities-repository' | ||
import { action, makeObservable, runInAction } from 'mobx' | ||
import { singleton } from 'tsyringe' | ||
import { IAction } from '../../../../shared/arch/interfaces/IAction' | ||
import { ActivityFormState } from '../state/activity-form-state' | ||
|
||
@singleton() | ||
export class GetActivityImageAction implements IAction<number> { | ||
constructor( | ||
private activitiesRepository: ActivitiesRepository, | ||
private activityFormState: ActivityFormState | ||
) { | ||
makeObservable(this) | ||
} | ||
|
||
@action | ||
async execute(activityId?: number): Promise<void> { | ||
const response = activityId | ||
? await this.activitiesRepository.getActivityImage(activityId) | ||
: null | ||
|
||
runInAction(() => { | ||
this.activityFormState.initialImageFile = response | ||
}) | ||
} | ||
} |
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