-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
<!-- You can erase any parts of this template not applicable to your Pull Request. --> **Fixes or implements VF-000** ### Checklist - [ ] this is a breaking change and should publish a new major version - [ ] appropriate tests have been written
- Loading branch information
Showing
13 changed files
with
128 additions
and
20 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
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,26 @@ | ||
import Fetch from '@api-sdk/fetch'; | ||
import { BaseModels } from '@voiceflow/base-types'; | ||
|
||
import BaseResource from './base'; | ||
|
||
export const ENDPOINT = 'notes'; | ||
|
||
export type ModelKey = 'id'; | ||
|
||
class NoteResource extends BaseResource<NoteResource> { | ||
constructor(fetch: Fetch) { | ||
super({ fetch, clazz: NoteResource, endpoint: ENDPOINT }); | ||
} | ||
|
||
public async upsert<T extends BaseModels.BaseNote = BaseModels.BaseNote>(versionID: string, note: T): Promise<T> { | ||
const { data } = await this.fetch.put<T>(`${this._getEndpoint()}/${versionID}`, { note }); | ||
|
||
return data; | ||
} | ||
|
||
public async delete(versionID: string, noteID: string): Promise<void> { | ||
await this.fetch.delete(`${this._getEndpoint()}/${versionID}/${noteID}`); | ||
} | ||
} | ||
|
||
export default NoteResource; |
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,49 @@ | ||
import { Note } from '@api-sdk/resources'; | ||
import { expect } from 'chai'; | ||
import sinon from 'sinon'; | ||
|
||
const NOTE = { id: 'qwe', text: 'text', mentions: [1, 2], meta: {} }; | ||
|
||
const createClient = () => { | ||
const fetch = { | ||
get: sinon.stub(), | ||
post: sinon.stub(), | ||
put: sinon.stub(), | ||
patch: sinon.stub(), | ||
delete: sinon.stub(), | ||
}; | ||
|
||
const resource = new Note(fetch as any); | ||
|
||
return { | ||
fetch, | ||
resource, | ||
}; | ||
}; | ||
|
||
describe('NoteResource', () => { | ||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('.upsert', async () => { | ||
const { fetch, resource } = createClient(); | ||
|
||
fetch.put.resolves({ data: NOTE }); | ||
|
||
const data = await resource.upsert('1', NOTE as any); | ||
|
||
expect(fetch.put.callCount).to.eql(1); | ||
expect(fetch.put.args[0]).to.eql([`notes/1`, { note: NOTE }]); | ||
expect(data).to.eql(NOTE); | ||
}); | ||
|
||
it('.delete', async () => { | ||
const { fetch, resource } = createClient(); | ||
|
||
await resource.delete('1', 'qwe'); | ||
|
||
expect(fetch.delete.callCount).to.eql(1); | ||
expect(fetch.delete.args[0]).to.eql([`notes/1/qwe`]); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -24,4 +24,5 @@ export interface Intent { | |
name: string; | ||
slots?: IntentSlot[]; | ||
inputs: IntentInput[]; | ||
noteID?: string; | ||
} |
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,24 @@ | ||
import { AnyRecord } from '@base-types/types'; | ||
|
||
export enum NoteType { | ||
INTENT = 'INTENT', | ||
} | ||
|
||
export interface BaseNote { | ||
id: string; | ||
type: NoteType; | ||
text: string; | ||
meta?: AnyRecord; | ||
mentions: number[]; | ||
} | ||
|
||
export interface IntentNoteMeta { | ||
intentID: string; | ||
} | ||
|
||
export interface IntentNote extends BaseNote { | ||
type: NoteType.INTENT; | ||
meta: IntentNoteMeta; | ||
} | ||
|
||
export type AnyNote = IntentNote; |
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