-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add custom fetcher config option #90
Open
jkcorrea
wants to merge
8
commits into
graphiti-api:master
Choose a base branch
from
jkcorrea:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+102
−13
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
dd25e4f
feat: add option for custom fetcher
jkcorrea 5dbf198
fix(ts): suppress property assignment error
jkcorrea fd8c601
add custom fetcher to all requests
jkcorrea 5d3439d
fix api for custom fetcher
jkcorrea f775579
add custom fetcher tests
jkcorrea 9db346c
add fetcher to model config
jkcorrea 9393050
add more custom fetcher tests
jkcorrea 8566f92
fix custom fetch types
jkcorrea File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,70 @@ | ||
import { expect, sinon } from "../test-helper" | ||
import fetchMock = require("fetch-mock") | ||
import { Model, SpraypaintBase } from "../../src" | ||
|
||
describe("Custom fetcher", () => { | ||
let spy1: sinon.SinonSpy | ||
let spy2: sinon.SinonSpy | ||
|
||
let ApplicationRecord: typeof SpraypaintBase | ||
let Author: typeof SpraypaintBase | ||
let Person: typeof SpraypaintBase | ||
|
||
beforeEach(() => { | ||
const fetcher = (a: any, b: any) => | ||
Promise.resolve( | ||
new Response( | ||
JSON.stringify({ | ||
data: { | ||
id: "1", | ||
type: "people", | ||
attributes: { | ||
firstName: "John" | ||
} | ||
} | ||
}) | ||
) | ||
) | ||
|
||
spy1 = sinon.spy(fetcher) | ||
spy2 = sinon.spy(fetcher) | ||
|
||
@Model({ | ||
baseUrl: "http://example.com", | ||
apiNamespace: "/api/v1" | ||
}) | ||
class Base extends SpraypaintBase {} | ||
ApplicationRecord = Base | ||
|
||
@Model({ | ||
jsonapiType: "authors", | ||
fetcher: spy1 | ||
}) | ||
class A extends ApplicationRecord {} | ||
Author = A | ||
|
||
@Model({ jsonapiType: "people" }) | ||
class B extends ApplicationRecord { | ||
static fetcher = spy2 | ||
} | ||
Person = B | ||
}) | ||
|
||
describe("uses custom fetchers", () => { | ||
it("calls a custom fetcher set via config", async () => { | ||
await Author.find(1) | ||
|
||
expect(spy1).to.have.been.calledOnce.and.to.have.been.calledWith( | ||
"http://example.com/api/v1/authors/1" | ||
) | ||
}) | ||
|
||
it("calls a custom fetcher set via static props", async () => { | ||
await Person.find(1) | ||
|
||
expect(spy2).to.have.been.calledOnce.and.to.have.been.calledWith( | ||
"http://example.com/api/v1/people/1" | ||
) | ||
}) | ||
}) | ||
}) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mind adding a spec which ensures that setting a single fetcher in the base class will allow both subclasses to use it?