diff --git a/lib/anydocs/deleteAnyDocumentTag.js b/lib/anydocs/deleteAnyDocumentTag.js new file mode 100644 index 0000000..3f3574e --- /dev/null +++ b/lib/anydocs/deleteAnyDocumentTag.js @@ -0,0 +1,14 @@ +const Client = require('../client/constructor'); +/** + * Unlink a tag from a specific any document. https://docs.veryfi.com/api/anydocs/unlink-a-tag-from-a-A-doc/ + * + * @memberof Client + * @param {string} document_id ID of the document you'd like to unlink the tag from + * @param {string} tag_id ID of the tag you'd like to unlink + * @return {JSON} response about the unlinked tag. + */ +Client.prototype.delete_any_document_tag = async function (document_id, tag_id) { + let endpoint_name = `/any-documents/${document_id}/tags/${tag_id}/`; + let request_arguments = {}; + return this._request("DELETE", endpoint_name, request_arguments); +} diff --git a/lib/client/client.js b/lib/client/client.js index d1d6675..caaeb71 100644 --- a/lib/client/client.js +++ b/lib/client/client.js @@ -1,5 +1,6 @@ const Client = require('../client/function'); require('../anydocs/deleteAnyDocument'); +require('../anydocs/deleteAnyDocumentTag'); require('../anydocs/getAnyDocument'); require('../anydocs/getAnyDocumentTags'); require('../anydocs/getAnyDocuments'); diff --git a/lib/types/Client.ts b/lib/types/Client.ts index 5ff7483..c5c662e 100644 --- a/lib/types/Client.ts +++ b/lib/types/Client.ts @@ -327,6 +327,16 @@ export declare class Client { public get_any_document_tags(document_id: number, {...kwargs}?: VeryfiExtraArgs): Promise<{tags: Tag[]}>; + /** + * Unlink a tag from a specific any document. https://docs.veryfi.com/api/anydocs/unlink-a-tag-from-a-A-doc/ + * + * @memberof Client + * @param {string} document_id ID of the document you'd like to unlink the tag from + * @param {string} tag_id ID of the tag you'd like to unlink + * @return {Promise} response about the unlinked tag. + */ + public delete_any_document_tag(document_id: string, tag_id: string): Promise; + /** * Process any document and extract all the fields from it. https://docs.veryfi.com/api/anydocs/process-%E2%88%80-doc/ * @example diff --git a/test/main.test.js b/test/main.test.js index 1d15836..135c1d2 100644 --- a/test/main.test.js +++ b/test/main.test.js @@ -377,6 +377,28 @@ describe('Processing any documents', () => { } }); + test('Unlink a tag from an any document', async () => { + try { + if (mock_responses) { + const mockResponse = require('../mocks/deleteTags.json'); + veryfi_client._request = jest.fn().mockResolvedValue(mockResponse); + } + const doc_id = 4559535; + const tag_id = 12345; + let response = await veryfi_client.delete_any_document_tag(doc_id, tag_id); + expect(response).toBeDefined(); + if (mock_responses) { + expect(veryfi_client._request).toHaveBeenCalledWith( + "DELETE", + `/any-documents/${doc_id}/tags/${tag_id}/`, + {} + ); + } + } catch (error) { + throw new Error(error); + } + }); + test('Get any document tags', async () => { try { if (mock_responses) { diff --git a/tests/main.test.ts b/tests/main.test.ts index d8e9c0d..2c765a1 100644 --- a/tests/main.test.ts +++ b/tests/main.test.ts @@ -511,6 +511,22 @@ describe('Processing any documents', () => { } }); + test('Unlink a tag from an any document', async () => { + try { + if (mock_responses) { + return assert(true) + } + let docs = await veryfi_client.get_any_documents(); + const doc_id = docs.results[0].id; + const tags = await veryfi_client.get_any_document_tags(doc_id); + const tag_id = tags.tags[0].id; + let response = await veryfi_client.delete_any_document_tag(doc_id, tag_id); + expect(response).toBeDefined(); + } catch (error) { + throw new Error(error); + } + }); + test('Get any document tags', async () => { try { if (mock_responses) {