-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
74 additions
and
12 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 |
---|---|---|
|
@@ -9,4 +9,10 @@ query listPosts @auth(level: PUBLIC) { | |
content | ||
} | ||
} | ||
query listPosts2 { | ||
posts { | ||
id, | ||
content | ||
} | ||
} | ||
|
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,39 @@ | ||
import { expect, use } from 'chai'; | ||
import { dcFetch, initializeFetch } from '../../src/network/fetch'; | ||
import chaiAsPromised from 'chai-as-promised'; | ||
import * as sinon from 'sinon'; | ||
use(chaiAsPromised); | ||
function mockFetch(json: any) { | ||
const fakeFetchImpl = sinon.stub().returns( | ||
Promise.resolve({ | ||
json: () => { | ||
return Promise.resolve(json); | ||
}, | ||
status: 401 | ||
} as Response) | ||
); | ||
initializeFetch(fakeFetchImpl); | ||
} | ||
describe('fetch', () => { | ||
it('should throw an error with just the message when the server responds with an error with a message property in the body', async () => { | ||
const message = 'Failed to connect to Postgres instance'; | ||
mockFetch({ | ||
code: 401, | ||
message | ||
}); | ||
await expect( | ||
dcFetch('http://localhost', {}, {} as AbortController, null) | ||
).to.eventually.be.rejectedWith(message); | ||
}); | ||
it('should throw a stringified message when the server responds with an error without a message property in the body', async () => { | ||
const message = 'Failed to connect to Postgres instance'; | ||
const json = { | ||
code: 401, | ||
message1: message | ||
} | ||
mockFetch(json); | ||
await expect( | ||
dcFetch('http://localhost', {}, {} as AbortController, null) | ||
).to.eventually.be.rejectedWith(JSON.stringify(json)); | ||
}); | ||
}); |
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