-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #155 from PermanentOrg/89-update-return-types
Throw on non-ok server responses
- Loading branch information
Showing
12 changed files
with
57 additions
and
55 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
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 |
---|---|---|
@@ -1,40 +1,37 @@ | ||
import nock from 'nock'; | ||
import { deleteFolderVo } from '..'; | ||
import { HttpResponseError } from '../../errors'; | ||
|
||
describe('deleteFolderVo', () => { | ||
it('should return true when a folder is deleted', async () => { | ||
it('should not throw when a folder is deleted', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/folder/delete?folderId=1', | ||
) | ||
.reply(200); | ||
|
||
const result = await deleteFolderVo( | ||
await expect(deleteFolderVo( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(true); | ||
)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should return false when a folder is not deleted', async () => { | ||
it('should throw an error when when a 500 status is returned', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/folder/delete?folderId=1', | ||
) | ||
.reply(500); | ||
|
||
const result = await deleteFolderVo( | ||
await expect(deleteFolderVo( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(false); | ||
)).rejects.toThrow(HttpResponseError); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,40 +1,37 @@ | ||
import nock from 'nock'; | ||
import { deleteRecordVo } from '..'; | ||
import { HttpResponseError } from '../../errors'; | ||
|
||
describe('deleteArchiveRecord', () => { | ||
it('should return true when a record is deleted', async () => { | ||
it('should not throw when a record is deleted', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/record/delete?recordId=1', | ||
) | ||
.reply(200); | ||
|
||
const result = await deleteRecordVo( | ||
await expect(deleteRecordVo( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(true); | ||
)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should return false when a record is not deleted', async () => { | ||
it('should throw an error when when a 500 status is returned', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/record/delete?recordId=1', | ||
) | ||
.reply(500); | ||
|
||
const result = await deleteRecordVo( | ||
await expect(deleteRecordVo( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(false); | ||
)).rejects.toThrow(HttpResponseError); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
export class HttpResponseError extends Error { | ||
public readonly statusCode: number; | ||
|
||
public constructor(statusCode: number, message: string) { | ||
super(message); | ||
this.statusCode = statusCode; | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './HttpResponseError'; | ||
export * from './ValidationError'; |
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 |
---|---|---|
@@ -1,40 +1,37 @@ | ||
import nock from 'nock'; | ||
import { deleteArchiveRecord } from '..'; | ||
import { HttpResponseError } from '../../errors'; | ||
|
||
describe('deleteArchiveRecord', () => { | ||
it('should return true when a record is deleted', async () => { | ||
it('should not throw on successful deletion', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/record/delete?recordId=1', | ||
) | ||
.reply(200); | ||
|
||
const result = await deleteArchiveRecord( | ||
await expect(deleteArchiveRecord( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(true); | ||
)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should return false when a record is not deleted', async () => { | ||
it('should throw an error when receiving a 500 response', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/record/delete?recordId=1', | ||
) | ||
.reply(500); | ||
|
||
const result = await deleteArchiveRecord( | ||
await expect(deleteArchiveRecord( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(false); | ||
)).rejects.toThrow(HttpResponseError); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,40 +1,37 @@ | ||
import nock from 'nock'; | ||
import { deleteFolder } from '..'; | ||
import { HttpResponseError } from '../../errors/HttpResponseError'; | ||
|
||
describe('deleteFolder', () => { | ||
it('should return true when a folder is deleted', async () => { | ||
it('should not throw when a folder is deleted', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/folder/delete?folderId=1', | ||
) | ||
.reply(200); | ||
|
||
const result = await deleteFolder( | ||
await expect(deleteFolder( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(true); | ||
)).resolves.not.toThrow(); | ||
}); | ||
|
||
it('should return false when a folder is not deleted', async () => { | ||
it('should throw an error when receiving a 500 response', async () => { | ||
nock('https://permanent.local') | ||
.delete( | ||
'/api/folder/delete?folderId=1', | ||
) | ||
.reply(500); | ||
|
||
const result = await deleteFolder( | ||
await expect(deleteFolder( | ||
{ | ||
bearerToken: '12345', | ||
baseUrl: 'https://permanent.local/api', | ||
}, | ||
1, | ||
); | ||
|
||
expect(result).toBe(false); | ||
)).rejects.toThrow(HttpResponseError); | ||
}); | ||
}); |
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