Skip to content

Commit

Permalink
Add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
JensAstrup committed Mar 31, 2024
1 parent a84823b commit bda2e43
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/base-class.test.js → tests/base-resource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ describe('ShortcutResource', () => {
expect(resource.name).toBe('Updated Name')
})

it('throws an error on update if operation is not available', async () => {
const resource = new ShortcutResource({id: 123})
resource.availableOperations = ['create']
resource.name = 'Updated Name'

await expect(resource.save()).rejects.toThrow('Update operation not available for this resource')
})

it('calls create if id does not exist', async () => {
const resource = new ShortcutResource()
resource.availableOperations = ['create']
Expand All @@ -51,6 +59,14 @@ describe('ShortcutResource', () => {
expect(resource.id).toBe(123)
expect(resource.name).toBe('New Name')
})

it('throws an error on create if operation is not available', async () => {
const resource = new ShortcutResource()
resource.availableOperations = ['update']
resource.name = 'New Name'

await expect(resource.save()).rejects.toThrow('Create operation not available for this resource')
})
})

describe('delete method', () => {
Expand All @@ -64,6 +80,13 @@ describe('ShortcutResource', () => {
expect(axios.delete).toHaveBeenCalledWith(expect.any(String), {headers: mockHeaders})
})

it('throws an error if delete operation is not available', async () => {
const resource = new ShortcutResource({id: 123})
resource.availableOperations = ['update']

await expect(resource.delete()).rejects.toThrow('Delete operation not available for this resource')
})

it('throws an error on delete failure', async () => {
const resource = new ShortcutResource({id: 123})
resource.availableOperations = ['delete']
Expand Down

0 comments on commit bda2e43

Please sign in to comment.