-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(PC-30787)[PRO] feat: can duplicate and can create bookable offer in …
…eac offer
- Loading branch information
1 parent
116db2c
commit 100af2e
Showing
5 changed files
with
147 additions
and
22 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
56 changes: 56 additions & 0 deletions
56
pro/src/utils/__specs__/isActionsAllowedOnCollectiveOffer.spec.tsx
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,56 @@ | ||
import { | ||
CollectiveOfferAllowedAction, | ||
CollectiveOfferTemplateAllowedAction, | ||
} from 'apiClient/v1' | ||
import { | ||
getCollectiveOfferFactory, | ||
getCollectiveOfferTemplateFactory, | ||
} from 'utils/collectiveApiFactories' | ||
import { isActionAllowedOnCollectiveOffer } from 'utils/isActionAllowedOnCollectiveOffer' | ||
|
||
describe('isActionAllowedOnCollectiveOffer', () => { | ||
it.each([ | ||
{ | ||
description: 'allowed action CAN_DUPLICATE on bookable offer ', | ||
offer: getCollectiveOfferFactory({ | ||
allowedActions: [CollectiveOfferAllowedAction.CAN_DUPLICATE], | ||
}), | ||
action: CollectiveOfferAllowedAction.CAN_DUPLICATE, | ||
expected: true, | ||
}, | ||
{ | ||
description: 'allowed action CAN_CREATE_BOOKABLE_OFFER on template offer', | ||
offer: getCollectiveOfferTemplateFactory({ | ||
allowedActions: [ | ||
CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER, | ||
], | ||
isTemplate: true, | ||
}), | ||
action: CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER, | ||
expected: true, | ||
}, | ||
{ | ||
description: 'not allowed action CAN_DUPLICATE on bookable offer ', | ||
offer: getCollectiveOfferFactory({ | ||
allowedActions: [], | ||
}), | ||
action: CollectiveOfferAllowedAction.CAN_DUPLICATE, | ||
expected: false, | ||
}, | ||
{ | ||
description: | ||
'not allowed action CAN_CREATE_BOOKABLE_OFFER on template offer', | ||
offer: getCollectiveOfferTemplateFactory({ | ||
allowedActions: [], | ||
isTemplate: true, | ||
}), | ||
action: CollectiveOfferTemplateAllowedAction.CAN_CREATE_BOOKABLE_OFFER, | ||
expected: false, | ||
}, | ||
])( | ||
'should return $expected for $description', | ||
({ offer, action, expected }) => { | ||
expect(isActionAllowedOnCollectiveOffer(offer, action)).toBe(expected) | ||
} | ||
) | ||
}) |
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 { | ||
CollectiveOfferAllowedAction, | ||
CollectiveOfferResponseModel, | ||
CollectiveOfferTemplateAllowedAction, | ||
GetCollectiveOfferResponseModel, | ||
GetCollectiveOfferTemplateResponseModel, | ||
} from 'apiClient/v1' | ||
import { | ||
isCollectiveOffer, | ||
isCollectiveOfferTemplate, | ||
} from 'core/OfferEducational/types' | ||
|
||
export function isActionAllowedOnCollectiveOffer( | ||
offer: | ||
| GetCollectiveOfferResponseModel | ||
| GetCollectiveOfferTemplateResponseModel | ||
| CollectiveOfferResponseModel, | ||
action: CollectiveOfferAllowedAction | CollectiveOfferTemplateAllowedAction | ||
) { | ||
if (isCollectiveOffer(offer)) { | ||
return offer.allowedActions.includes(action as CollectiveOfferAllowedAction) | ||
} | ||
|
||
if (isCollectiveOfferTemplate(offer)) { | ||
return offer.allowedActions.includes( | ||
action as CollectiveOfferTemplateAllowedAction | ||
) | ||
} | ||
|
||
return false | ||
} |