-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: videos will show only to bnr active subscriptions (#1249)
- Loading branch information
1 parent
02686b1
commit bc78166
Showing
12 changed files
with
136 additions
and
79 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
14 changes: 14 additions & 0 deletions
14
src/components/app/data/hooks/useHasValidLicenseOrSubscriptionRequestsEnabled.js
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,14 @@ | ||
import { SUBSIDY_TYPE } from '../../../../constants'; | ||
import { LICENSE_STATUS } from '../../../enterprise-user-subsidy/data/constants'; | ||
import { useBrowseAndRequestConfiguration } from './useBrowseAndRequest'; | ||
import useSubscriptions from './useSubscriptions'; | ||
|
||
export default function useHasValidLicenseOrSubscriptionRequestsEnabled() { | ||
const { data: { subscriptionLicense } } = useSubscriptions(); | ||
const { data: browseAndRequestConfiguration } = useBrowseAndRequestConfiguration(); | ||
const hasActivatedAndCurrentLicense = subscriptionLicense?.status === LICENSE_STATUS.ACTIVATED | ||
&& subscriptionLicense?.subscriptionPlan?.isCurrent; | ||
const hasRequestsEnabledForSubscriptions = browseAndRequestConfiguration?.subsidyRequestsEnabled | ||
&& browseAndRequestConfiguration.subsidyType === SUBSIDY_TYPE.LICENSE; | ||
return hasActivatedAndCurrentLicense || hasRequestsEnabledForSubscriptions; | ||
} |
94 changes: 94 additions & 0 deletions
94
src/components/app/data/hooks/useHasValidLicenseOrSubscriptionRequestsEnabled.test.jsx
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,94 @@ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import useHasValidLicenseOrSubscriptionRequestsEnabled from './useHasValidLicenseOrSubscriptionRequestsEnabled'; | ||
import { LICENSE_STATUS } from '../../../enterprise-user-subsidy/data/constants'; | ||
import { SUBSIDY_TYPE } from '../../../../constants'; | ||
import { useBrowseAndRequestConfiguration } from './useBrowseAndRequest'; | ||
import useSubscriptions from './useSubscriptions'; | ||
|
||
jest.mock('./useBrowseAndRequest'); | ||
jest.mock('./useSubscriptions'); | ||
|
||
describe('useHasValidLicenseOrSubscriptionRequestsEnabled', () => { | ||
it('should return true when the subscription license is activated and current', () => { | ||
useSubscriptions.mockReturnValue({ | ||
data: { | ||
subscriptionLicense: { | ||
status: LICENSE_STATUS.ACTIVATED, | ||
subscriptionPlan: { | ||
isCurrent: true, | ||
}, | ||
}, | ||
}, | ||
}); | ||
useBrowseAndRequestConfiguration.mockReturnValue({ | ||
data: { | ||
subsidyRequestsEnabled: false, | ||
subsidyType: SUBSIDY_TYPE.LICENSE, | ||
}, | ||
}); | ||
|
||
const { result } = renderHook(() => useHasValidLicenseOrSubscriptionRequestsEnabled()); | ||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it('should return true when subsidy requests are enabled for subscriptions', () => { | ||
useSubscriptions.mockReturnValue({ | ||
data: { | ||
subscriptionLicense: { | ||
status: LICENSE_STATUS.REVOKED, | ||
subscriptionPlan: { | ||
isCurrent: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
useBrowseAndRequestConfiguration.mockReturnValue({ | ||
data: { | ||
subsidyRequestsEnabled: true, | ||
subsidyType: SUBSIDY_TYPE.LICENSE, | ||
}, | ||
}); | ||
|
||
const { result } = renderHook(() => useHasValidLicenseOrSubscriptionRequestsEnabled()); | ||
expect(result.current).toBe(true); | ||
}); | ||
|
||
it('should return false when the subscription license is not activated and not current, and subsidy requests are not enabled', () => { | ||
useSubscriptions.mockReturnValue({ | ||
data: { | ||
subscriptionLicense: { | ||
status: LICENSE_STATUS.REVOKED, | ||
subscriptionPlan: { | ||
isCurrent: false, | ||
}, | ||
}, | ||
}, | ||
}); | ||
useBrowseAndRequestConfiguration.mockReturnValue({ | ||
data: { | ||
subsidyRequestsEnabled: false, | ||
subsidyType: SUBSIDY_TYPE.LICENSE, | ||
}, | ||
}); | ||
|
||
const { result } = renderHook(() => useHasValidLicenseOrSubscriptionRequestsEnabled()); | ||
expect(result.current).toBe(false); | ||
}); | ||
|
||
it('should return false when subscriptionLicense is undefined and subsidy requests are not enabled', () => { | ||
useSubscriptions.mockReturnValue({ | ||
data: { | ||
subscriptionLicense: undefined, | ||
}, | ||
}); | ||
useBrowseAndRequestConfiguration.mockReturnValue({ | ||
data: { | ||
subsidyRequestsEnabled: false, | ||
subsidyType: SUBSIDY_TYPE.LICENSE, | ||
}, | ||
}); | ||
|
||
const { result } = renderHook(() => useHasValidLicenseOrSubscriptionRequestsEnabled()); | ||
expect(result.current).toBe(false); | ||
}); | ||
}); |
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
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
Oops, something went wrong.