Skip to content

Commit

Permalink
change pickoncollect to property
Browse files Browse the repository at this point in the history
  • Loading branch information
Petter Andersson committed Jan 30, 2025
1 parent 377e2ab commit a73ed02
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/adverts/advert-mutations/claims/cancel-advert-claim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { makeUser } from '../../../login'
import { TxErrors, txBuilder } from '../../../transactions'
import type { Services } from '../../../types'
import { normalizeAdvertClaims } from '../../advert-claims'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,13 @@ describe('convertAdvertClaim - picking', () => {
advertWasCollected,
advertWasCollectedOwner,
})
const doPickOnCollect = jest.fn(() => true)
const workflow = {
doPickOnCollect,
get pickOnCollect() {
return true
},
}
const spy = jest.spyOn(workflow, 'pickOnCollect', 'get')

return end2endTest(
{
services: { notifications, workflow },
Expand Down Expand Up @@ -195,7 +198,7 @@ describe('convertAdvertClaim - picking', () => {
)
)
T('should have checked configuration', () =>
expect(doPickOnCollect).toHaveBeenCalled()
expect(spy).toHaveBeenCalled()
)
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/adverts/advert-mutations/claims/convert-advert-claim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const createConvertAdvertClaim =
({
adverts,
notifications,
workflow,
workflow: { pickOnCollect },
}: Pick<
Services,
'adverts' | 'notifications' | 'workflow'
Expand Down Expand Up @@ -63,7 +63,7 @@ export const createConvertAdvertClaim =
)
)
const pickedAt =
newType === AdvertClaimType.collected && workflow.doPickOnCollect()
newType === AdvertClaimType.collected && pickOnCollect
? at
: advert.pickedAt

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ describe('collectAdvert', () => {
advertWasCollected,
advertWasCollectedOwner,
})
const doPickOnCollect = jest.fn(() => true)
const workflow = {
doPickOnCollect,
get pickOnCollect() {
return true
},
}
const spy = jest.spyOn(workflow, 'pickOnCollect', 'get')

return end2endTest(
{ services: { notifications, workflow } },
Expand Down Expand Up @@ -184,7 +186,7 @@ describe('collectAdvert', () => {
)

T('should have checked configuration', () =>
expect(doPickOnCollect).toHaveBeenCalled()
expect(spy).toHaveBeenCalled()
)
}
)
Expand Down
4 changes: 2 additions & 2 deletions src/adverts/advert-mutations/collecting/collect-advert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const createCollectAdvert =
({
adverts,
notifications,
workflow,
workflow: { pickOnCollect },
}: Pick<
Services,
'adverts' | 'notifications' | 'workflow'
Expand Down Expand Up @@ -63,7 +63,7 @@ export const createCollectAdvert =
.map(({ quantity }) => quantity)
.reduce((s, v) => s + v, 0)

const pickedAt = workflow.doPickOnCollect() ? at : advert.pickedAt
const pickedAt = pickOnCollect ? at : advert.pickedAt

return {
...advert,
Expand Down
4 changes: 3 additions & 1 deletion src/test-utils/test-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,9 @@ export const createTestNotificationServices = (

export const createTestServices = (services: Partial<Services>): Services => {
const workflow = {
doPickOnCollect: () => false,
get pickOnCollect() {
return false
},
}
const settings = services.settings || createInMemorySettingsService()
const userMapper = services.userMapper || createUserMapper(null, settings)
Expand Down
5 changes: 3 additions & 2 deletions src/workflow/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getEnv } from '../lib/gdi-api-node'
import type { WorkflowService } from './types'

export const createWorkflowServiceFromEnv = (): WorkflowService => ({
doPickOnCollect: () =>
Number(getEnv('PICK_ON_COLLECT', { fallback: '0' })) === 1,
get pickOnCollect() {
return Number(getEnv('PICK_ON_COLLECT', { fallback: '0' })) === 1
},
})
2 changes: 1 addition & 1 deletion src/workflow/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export interface WorkflowService {
doPickOnCollect: () => boolean
pickOnCollect: boolean
}

0 comments on commit a73ed02

Please sign in to comment.