Skip to content

Commit

Permalink
test(core): update useReleaseOperations tests
Browse files Browse the repository at this point in the history
  • Loading branch information
RitaDias committed Feb 11, 2025
1 parent c390bb7 commit d298eae
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export const useReleaseOperationsMockReturn: Mocked<ReleaseOperationsStore> = {
deleteRelease: vi.fn(),
revertRelease: vi.fn(),
unpublishVersion: vi.fn(),
canPublish: vi.fn(),
canSchedule: vi.fn(),
}

export const mockUseReleaseOperations = useReleaseOperations as Mock<typeof useReleaseOperations>
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ describe('createReleaseOperationsStore', () => {
}
})

const createStore = () => createReleaseOperationsStore({client: mockClient})
const createStore = () =>
createReleaseOperationsStore({
client: mockClient,
onReleaseLimitReached: vi.fn(),
})

it('should create a release', async () => {
const store = createStore()
Expand Down Expand Up @@ -352,4 +356,45 @@ describe('createReleaseOperationsStore', () => {
},
})
})

describe('permissions', () => {
it('should check if it has permission to publish a release', async () => {
const store = createStore()
await store.canPublish('_.releases.release-id', true)
expect(mockClient.request).toHaveBeenCalledWith({
uri: '/data/actions/test-dataset',
method: 'POST',
body: {
dryRun: true,
skipCrossDatasetReferenceValidation: true,
actions: [
{
actionType: 'sanity.action.release.publish2',
releaseId: 'release-id',
},
],
},
})
})

it('should check if it has permission to schedule a release', async () => {
const store = createStore()
await store.canSchedule('_.releases.release-id', new Date('2024-01-01T00:00:00Z'))
expect(mockClient.request).toHaveBeenCalledWith({
uri: '/data/actions/test-dataset',
method: 'POST',
body: {
dryRun: true,
skipCrossDatasetReferenceValidation: true,
actions: [
{
actionType: 'sanity.action.release.schedule',
releaseId: 'release-id',
publishAt: '2024-01-01T00:00:00.000Z',
},
],
},
})
})
})
})

0 comments on commit d298eae

Please sign in to comment.