Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
53 changes: 7 additions & 46 deletions packages/core/src/auth/authStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ describe('authStore', () => {
const storageArea = {} as Storage

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
apiHost,
callbackUrl,
Expand Down Expand Up @@ -109,8 +107,6 @@ describe('authStore', () => {
const context = {mode: 'test', env: 'staging', orgId: 'abc'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -124,8 +120,6 @@ describe('authStore', () => {
const expectedContext = {mode: 'test', env: 'staging', orgId: 'abc'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -138,8 +132,6 @@ describe('authStore', () => {
const initialLocationHref = `https://example.com/?_context=invalid-json`
const errorSpy = vi.spyOn(console, 'error').mockImplementation(() => {})
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -158,8 +150,6 @@ describe('authStore', () => {
const context = {mode: 'dashboard'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
token,
initialLocationHref,
Expand All @@ -175,8 +165,6 @@ describe('authStore', () => {
const context = {orgId: 'org1'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -189,10 +177,7 @@ describe('authStore', () => {

it('sets to logged in from storage token when NOT in dashboard', () => {
const storageToken = 'storage-token'
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
})
instance = createSanityInstance()

vi.mocked(getAuthCode).mockReturnValue(null)
vi.mocked(getTokenFromStorage).mockReturnValue(storageToken)
Expand All @@ -207,8 +192,6 @@ describe('authStore', () => {
const context = {mode: 'dashboard'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -221,10 +204,7 @@ describe('authStore', () => {
})

it('sets the state to logged out when no token, code, or context', () => {
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
})
instance = createSanityInstance()

vi.mocked(getAuthCode).mockReturnValue(null)
vi.mocked(getTokenFromStorage).mockReturnValue(null)
Expand Down Expand Up @@ -292,10 +272,7 @@ describe('authStore', () => {
const storageToken = 'regular-storage-token'
vi.mocked(getTokenFromStorage).mockReturnValue(storageToken)

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
})
instance = createSanityInstance()

const {authState, options} = authStore.getInitialState(instance, null)
expect(getStudioTokenFromLocalStorage).not.toHaveBeenCalled()
Expand All @@ -307,8 +284,6 @@ describe('authStore', () => {
it('sets to logging in if getTokenFromLocation returns a token', () => {
const initialLocationHref = 'https://example.com/#token=hash-token'
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand Down Expand Up @@ -363,8 +338,6 @@ describe('authStore', () => {

it('subscribes to state and storage events and unsubscribes on dispose', () => {
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {storageArea: mockLocalStorage},
})

Expand All @@ -389,8 +362,6 @@ describe('authStore', () => {

it('does not subscribe to storage events when not using storage area', () => {
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {storageArea: undefined},
})

Expand Down Expand Up @@ -431,7 +402,7 @@ describe('authStore', () => {
return NEVER.subscribe()
})

instance = createSanityInstance({projectId: 'p', dataset: 'd'})
instance = createSanityInstance()

const {getCurrent} = getCurrentUserState(instance)

Expand All @@ -440,7 +411,7 @@ describe('authStore', () => {
})

it('returns null otherwise', () => {
instance = createSanityInstance({projectId: 'p', dataset: 'd'})
instance = createSanityInstance()
const {getCurrent} = getCurrentUserState(instance)
expect(getCurrent()).toBe(null)
})
Expand All @@ -456,8 +427,6 @@ describe('authStore', () => {
it('returns the token if logged in', () => {
const token = 'hard-coded-token'
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {token},
})
const tokenState = getTokenState(instance)
Expand All @@ -468,7 +437,7 @@ describe('authStore', () => {
})

it('returns null otherwise', () => {
instance = createSanityInstance({projectId: 'p', dataset: 'd'})
instance = createSanityInstance()

const tokenState = getTokenState(instance)
expect(tokenState.getCurrent()).toBe(null)
Expand All @@ -486,7 +455,7 @@ describe('authStore', () => {
})

it('returns the default login url', () => {
instance = createSanityInstance({projectId: 'p', dataset: 'd'})
instance = createSanityInstance()

const loginUrlState = getLoginUrlState(instance)
expect(loginUrlState.getCurrent()).toBe(
Expand All @@ -504,8 +473,6 @@ describe('authStore', () => {

it('returns the current state in `authState`', () => {
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {token: 'hard-coded-token'},
})

Expand Down Expand Up @@ -536,8 +503,6 @@ describe('authStore', () => {
const context = {orgId: 'initial-org-id'}
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand All @@ -554,8 +519,6 @@ describe('authStore', () => {
const authCode = 'test-auth-code'

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory: () => mockClient as unknown as SanityClient,
initialLocationHref, // Set initial context
Expand Down Expand Up @@ -591,8 +554,6 @@ describe('authStore', () => {
const context = {mode: 'test'} // No orgId
const initialLocationHref = `https://example.com/?_context=${encodeURIComponent(JSON.stringify(context))}`
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {initialLocationHref},
})

Expand Down
12 changes: 0 additions & 12 deletions packages/core/src/auth/handleAuthCallback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ describe('handleCallback', () => {
vi.mocked(getAuthCode).mockReturnValue(authCode)

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem} as unknown as Storage,
Expand Down Expand Up @@ -89,8 +87,6 @@ describe('handleCallback', () => {
vi.mocked(getAuthCode).mockReturnValue(authCode)

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem} as unknown as Storage,
Expand Down Expand Up @@ -119,8 +115,6 @@ describe('handleCallback', () => {
const setItem = vi.fn()

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem: setItem as Storage['setItem']} as Storage,
Expand Down Expand Up @@ -161,8 +155,6 @@ describe('handleCallback', () => {
const setItem = vi.fn()

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem} as unknown as Storage,
Expand Down Expand Up @@ -190,8 +182,6 @@ describe('handleCallback', () => {
vi.mocked(getAuthCode).mockReturnValue(authCode)

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem} as unknown as Storage,
Expand Down Expand Up @@ -229,8 +219,6 @@ describe('handleCallback', () => {
vi.mocked(getTokenFromLocation).mockReturnValue('hash-token')

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {setItem} as unknown as Storage,
Expand Down
6 changes: 0 additions & 6 deletions packages/core/src/auth/logout.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ describe('logout', () => {
const removeItem = vi.fn() as Storage['removeItem']

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {removeItem} as Storage,
Expand Down Expand Up @@ -67,8 +65,6 @@ describe('logout', () => {
const clientFactory = vi.fn()
const removeItem = vi.fn() as Storage['removeItem']
instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
token: 'provided-token',
clientFactory,
Expand All @@ -93,8 +89,6 @@ describe('logout', () => {
vi.mocked(getTokenFromStorage).mockReturnValue('token')

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {
clientFactory,
storageArea: {removeItem} as Storage,
Expand Down
16 changes: 0 additions & 16 deletions packages/core/src/auth/refreshStampedToken.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ describe('refreshStampedToken', () => {
}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -164,8 +162,6 @@ describe('refreshStampedToken', () => {
}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -198,8 +194,6 @@ describe('refreshStampedToken', () => {
const mockClient = {observable: {request: vi.fn()}}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -249,8 +243,6 @@ describe('refreshStampedToken', () => {
}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -299,8 +291,6 @@ describe('refreshStampedToken', () => {
}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -345,8 +335,6 @@ describe('refreshStampedToken', () => {
const mockClient = {observable: {request: vi.fn(() => throwError(() => error))}}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down Expand Up @@ -374,8 +362,6 @@ describe('refreshStampedToken', () => {
it('does nothing if user is not logged in', async () => {
const mockClientFactory = vi.fn()
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand All @@ -400,8 +386,6 @@ describe('refreshStampedToken', () => {
const mockClient = {observable: {request: vi.fn()}}
const mockClientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {clientFactory: mockClientFactory, storageArea: mockStorage},
})
const initialState = authStore.getInitialState(instance, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('subscribeToStateAndFetchCurrentUser', () => {
const mockRequest = vi.fn().mockReturnValue(of(mockUser))
const mockClient = {observable: {request: mockRequest}}
const clientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({projectId: 'p', dataset: 'd', auth: {clientFactory}})
const instance = createSanityInstance({auth: {clientFactory}})

const state = createStoreState(authStore.getInitialState(instance, null))
const subscription = subscribeToStateAndFetchCurrentUser({state, instance, key: null})
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('subscribeToStateAndFetchCurrentUser', () => {
const mockRequest = vi.fn().mockReturnValue(of(mockUser).pipe(delay(0)))
const mockClient = {observable: {request: mockRequest}}
const clientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({projectId: 'p', dataset: 'd', auth: {clientFactory}})
const instance = createSanityInstance({auth: {clientFactory}})

const state = createStoreState(authStore.getInitialState(instance, null))
const subscription = subscribeToStateAndFetchCurrentUser({state, instance, key: null})
Expand Down Expand Up @@ -86,7 +86,7 @@ describe('subscribeToStateAndFetchCurrentUser', () => {
const mockRequest = vi.fn().mockReturnValue(throwError(() => error))
const mockClient = {observable: {request: mockRequest}}
const clientFactory = vi.fn().mockReturnValue(mockClient)
const instance = createSanityInstance({projectId: 'p', dataset: 'd', auth: {clientFactory}})
const instance = createSanityInstance({auth: {clientFactory}})

const state = createStoreState(authStore.getInitialState(instance, null))
const subscription = subscribeToStateAndFetchCurrentUser({state, instance, key: null})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ describe('subscribeToStorageEventsAndSetToken', () => {
vi.clearAllMocks()

instance = createSanityInstance({
projectId: 'p',
dataset: 'd',
auth: {storageArea: storageArea},
})

Expand Down
Loading
Loading