Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Refactor useAccessAndRemixSettings & add unit test #8049

Merged
merged 33 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
f006872
add contextual menu & remove extra options
DejayJD Mar 26, 2024
505b6c9
update access menu fields
DejayJD Mar 26, 2024
8d145a9
Update the access options for albums
DejayJD Mar 26, 2024
f3b63d4
semi-working wip
DejayJD Mar 27, 2024
394c4ec
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Mar 27, 2024
64dcbed
add preview time
DejayJD Mar 27, 2024
0d0d757
change to not spread existing obj
DejayJD Mar 27, 2024
230fdc5
fix upload by setting download conditions
DejayJD Mar 27, 2024
8db8717
working upload of premium albums
DejayJD Mar 27, 2024
f143aed
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Mar 27, 2024
2fc942a
Fixed uploads showing incorrectly for uploader, added feature flag lo…
DejayJD Mar 28, 2024
b4287e5
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Mar 29, 2024
f2a3a1e
test & types
DejayJD Mar 29, 2024
635bdb4
Clean up how sagas modify metadata
DejayJD Mar 29, 2024
6d96d8e
fix react dupe key error
DejayJD Mar 29, 2024
dc70c93
working tests (in theory)
DejayJD Apr 2, 2024
49bb98f
resolve type issues
DejayJD Apr 2, 2024
4d4a561
fix lint
DejayJD Apr 2, 2024
755c793
fix pw test
DejayJD Apr 2, 2024
f5fe3fa
make stream conditions optional (should fix tests)
DejayJD Apr 2, 2024
6572750
Update packages/common/src/models/Track.ts
DejayJD Apr 3, 2024
bb5acb7
PR feedback
DejayJD Apr 3, 2024
84fffe9
Merge branch 'jd-premium-album-upload' of github.com:AudiusProject/au…
DejayJD Apr 3, 2024
fc7e287
fix litn
DejayJD Apr 3, 2024
650df38
actually fix lint
DejayJD Apr 3, 2024
acb4e34
tweak flag behavior
DejayJD Apr 3, 2024
9afde65
commit changes so I can merge main
DejayJD Apr 3, 2024
4c98f25
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Apr 3, 2024
743de5e
Finish test & remove logs
DejayJD Apr 3, 2024
3dab3ba
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Apr 8, 2024
30babca
fix ts/lint
DejayJD Apr 8, 2024
5583fdc
Merge branch 'main' of github.com:AudiusProject/audius-protocol into …
DejayJD Apr 9, 2024
29f4ed1
fix lint
DejayJD Apr 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
336 changes: 336 additions & 0 deletions packages/common/src/hooks/useAccessAndRemixSettings.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,336 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'

import {
AccessConditionsEthNFTCollection,
Chain,
Collectible,
CollectibleGatedConditions,
CollectibleMediaType,
FollowGatedConditions,
TipGatedConditions,
USDCPurchaseConditions
} from '~/models'

import { useAccessAndRemixSettings } from './useAccessAndRemixSettings'

const { mockedUseSelector } = vi.hoisted(() => {
return { mockedUseSelector: vi.fn() }
})

vi.mock('react-redux', () => {
return {
useSelector: mockedUseSelector
}
})

const mockUseSelector = (mockedState: any) => (selectorFn: any) =>
selectorFn(mockedState)

const mockEthCollectible: Collectible = {
id: '123',
tokenId: '123',
name: 'dank nft',
description: 'dank nft description',
mediaType: CollectibleMediaType.IMAGE,
frameUrl: 'danknft.com/eth/frameUrl',
imageUrl: 'danknft.com/eth/imageUrl',
gifUrl: 'danknft.com/eth/gifUrl',
videoUrl: 'danknft.com/eth/videoUrl',
threeDUrl: 'danknft.com/eth/threeDUrl',
animationUrl: 'danknft.com/eth/animationUrl',
hasAudio: false,
isOwned: true,
dateCreated: '01-01-2020',
dateLastTransferred: '01-01-2020',
chain: Chain.Eth,
permaLink: 'danknft.com/eth/permaLink',
wallet: 'pretendThisIsAWalletAddress',
collectionName: 'dank nft',
collectionSlug: 'dank-nft',
collectionImageUrl: 'danknft.com/img',
assetContractAddress: 'pretendThisIsAnAddress',
externalLink: 'danknft.com/eth/pretendThisIsAnAddress',
standard: 'ERC721'
}

const mockUSDCGateConditions: USDCPurchaseConditions = {
usdc_purchase: {
price: 100,
splits: { 123: 100 }
}
}

const mockFollowGateConditions: FollowGatedConditions = {
follow_user_id: 123
}
const mockTipGateConditions: TipGatedConditions = {
tip_user_id: 123
}

const mockCollectibleGateConditions: CollectibleGatedConditions = {
nft_collection: {
...mockEthCollectible,
address: 'someAddress',
slug: 'slug'
} as AccessConditionsEthNFTCollection
}

const reduxStateWithoutCollectibles = {
account: {
userId: 123
},
collectibles: {
userCollectibles: { 123: { sol: [], eth: [] } },
solCollections: {}
}
}

const reduxStateWithCollectibles = {
account: {
userId: 123
},
collectibles: {
userCollectibles: {
123: { sol: [], eth: [mockEthCollectible] }
},
solCollections: {}
}
}

describe('useAccessAndRemixSettings', () => {
beforeEach(() => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithoutCollectibles)
)
})
describe('track upload', () => {
it('should support all options when the user has collectibles', () => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithCollectibles)
)
const actual = useAccessAndRemixSettings({
isUpload: true,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: false,
disableCollectibleGate: false,
disableCollectibleGateFields: false,
disableHidden: false
}
expect(actual).toEqual(expected)
})
it('should disable collectibles if the user has none', () => {
const actual = useAccessAndRemixSettings({
isUpload: true,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: false,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: false
}
expect(actual).toEqual(expected)
})
it('should disable all except hidden for track remixes', () => {
const actual = useAccessAndRemixSettings({
isUpload: true,
isRemix: true,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: true,
disableSpecialAccessGate: true,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: false
}
expect(actual).toEqual(expected)
})
})
describe('track edit', () => {
it('public track - should disable all options', () => {
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: true,
disableSpecialAccessGate: true,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('scheduled release - should allow everything except hidden', () => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithCollectibles)
)
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: true,
isScheduledRelease: true
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: false,
disableCollectibleGate: false,
disableCollectibleGateFields: false,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('follow gated - should disable everything except original parent option & hidden', () => {
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: mockFollowGateConditions,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: true,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('follow gated - should disable everything except original parent option & hidden', () => {
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: mockTipGateConditions,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: true,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('collectible gated - should disable everything except original parent option & hidden', () => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithCollectibles)
)
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: mockCollectibleGateConditions,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: true,
disableSpecialAccessGate: true,
disableSpecialAccessGateFields: true,
disableCollectibleGate: false,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('usdc gated - should disable everything except original parent option & hidden', () => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithCollectibles)
)
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: mockUSDCGateConditions,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: true,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
it('initially hidden - should enable everything', () => {
mockedUseSelector.mockImplementation(
mockUseSelector(reduxStateWithCollectibles)
)
const actual = useAccessAndRemixSettings({
isUpload: false,
isRemix: false,
isAlbum: undefined,
initialStreamConditions: null,
isInitiallyUnlisted: true,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: false,
disableSpecialAccessGateFields: false,
disableCollectibleGate: false,
disableCollectibleGateFields: false,
disableHidden: false
}
expect(actual).toEqual(expected)
})
})
describe('album upload', () => {
it('should only allow usdc for album uploads', () => {
const actual = useAccessAndRemixSettings({
isUpload: true,
isRemix: false,
isAlbum: true,
initialStreamConditions: null,
isInitiallyUnlisted: false,
isScheduledRelease: false
})
const expected = {
disableUsdcGate: false,
disableSpecialAccessGate: true,
disableSpecialAccessGateFields: true,
disableCollectibleGate: true,
disableCollectibleGateFields: true,
disableHidden: true
}
expect(actual).toEqual(expected)
})
})
})
Loading