Skip to content
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

Cache invalidation by "endpoint.invalidate" #266

Merged
merged 1 commit into from
Sep 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions packages/lib-js-core/src/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import QueryBuilder from './query-builder'
* Running endpoints.
* @property {Function}
* @example {@lang javascript}
* const latestTags = await socket.get('tags/list', { sort: 'latest' })
* const createdTag = await socket.post('tags/create', { name: 'nature' })
* const latestTags = await endpoint.get('tags/list', { sort: 'latest' })
* const createdTag = await endpoint.post('tags/create', { name: 'nature' })
*/
export default class Endpoint extends QueryBuilder {
post (endpoint, body = {}, options = {}) {
Expand Down Expand Up @@ -34,6 +34,10 @@ export default class Endpoint extends QueryBuilder {
return this.post(endpoint, {...data, _method: 'PATCH'}, options)
}

invalidate (endpoint) {
return this.fetch(`${this._url(endpoint)}invalidate`, {method: 'POST'})
}

_url (endpoint) {
const {instanceName} = this.instance

Expand Down
10 changes: 10 additions & 0 deletions packages/lib-js-core/test/unit/endpoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,14 @@ describe('Endpoint', () => {
.fulfilled
})
})

describe('#invalidate', () => {
it('should send POST request', () => {
api
.post(`${testEndpoint}invalidate`)
.reply(200)

return endpoint.invalidate('socket/endpoint').should.be.fulfilled
})
})
})