From 3e2dcd1a61143c074b94c645394baec8a818388a Mon Sep 17 00:00:00 2001 From: newhouse Date: Mon, 14 Dec 2020 17:57:48 -0800 Subject: [PATCH 1/3] gets pdf info --- src/graphql/queries/getPDFInfo.js | 13 +++++++++++++ src/index.js | 18 ++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 src/graphql/queries/getPDFInfo.js diff --git a/src/graphql/queries/getPDFInfo.js b/src/graphql/queries/getPDFInfo.js new file mode 100644 index 0000000..84bf5d6 --- /dev/null +++ b/src/graphql/queries/getPDFInfo.js @@ -0,0 +1,13 @@ +module.exports = { + generateQuery: () => ` + query GetPDFInfo ( + $castEid: String, + $file: Upload, + ) { + getPDFInfo ( + castEid: $castEid, + file: $file, + ) + } + `, +} diff --git a/src/index.js b/src/index.js index 7c03a8f..5ba59f0 100644 --- a/src/index.js +++ b/src/index.js @@ -22,6 +22,9 @@ const { etchPacket: { generateQuery: generateEtchPacketQuery, }, + getPDFInfo: { + generateQuery: generateGetPDFInfoQuery, + }, }, } = require('./graphql') @@ -136,6 +139,21 @@ class Anvil { ) } + getPDFInfo ({ variables }) { + console.log({ + getPDFInfo: { + variables, + } + }) + return this.requestGraphQL( + { + query: generateGetPDFInfoQuery(), + variables, + }, + { dataType: DATA_TYPE_JSON }, + ) + } + createEtchPacket ({ variables, responseQuery, mutation }) { return this.requestGraphQL( { From 639c72c602401ec0c78c2460cd622afbdcec49e6 Mon Sep 17 00:00:00 2001 From: newhouse Date: Tue, 15 Dec 2020 18:18:58 -0800 Subject: [PATCH 2/3] getPDFInfo --- README.md | 8 ++++++ src/index.js | 5 ---- test/index.test.js | 64 +++++++++++++++++++++++++++------------------- 3 files changed, 45 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 0931fdf..7e6bcec 100644 --- a/README.md +++ b/README.md @@ -201,6 +201,14 @@ Gets the details of an Etch Packet. * `eid` (String) - your Etch Packet eid * `responseQuery` (String) - _optional_ A GraphQL Query compliant query to use for the data desired in the query response. Can be left out to use default. +##### getPDFInfo(options) + +Gets the details of a PDF. +* `options` (Object) - An object with the following structure: + * `variables` (Object) - An object with the following structure: + * `castEid`: The EID of an existing Cast. + * `file`: Either a binary file (see [`prepareGraphQLFile`](#preparegraphqlfilepathorstreamlikething-options)) or a base64-encoded string in the same structure we support for the `createEtchPacket` mutation. See the [API Documentation](#api-documentation) for more. + ##### generateEtchSignUrl(options) Generates an Etch sign URL for an Etch Packet signer. The Etch Packet and its signers must have already been created. diff --git a/src/index.js b/src/index.js index 5ba59f0..97eb241 100644 --- a/src/index.js +++ b/src/index.js @@ -140,11 +140,6 @@ class Anvil { } getPDFInfo ({ variables }) { - console.log({ - getPDFInfo: { - variables, - } - }) return this.requestGraphQL( { query: generateGetPDFInfoQuery(), diff --git a/test/index.test.js b/test/index.test.js index 081bf7a..163c7eb 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -42,6 +42,12 @@ function mockNodeFetchResponse (options = {}) { } describe('Anvil API Client', function () { + const sandbox = sinon.createSandbox() + + afterEach(async function () { + sandbox.restore() + }) + describe('constructor', function () { it('throws an error when no options specified', async function () { expect(() => new Anvil()).to.throw('options are required') @@ -69,7 +75,7 @@ describe('Anvil API Client', function () { beforeEach(async function () { client = new Anvil({ apiKey: 'abc123' }) - sinon.stub(client, '_request') + sandbox.stub(client, '_request') }) describe('requestREST', function () { @@ -372,14 +378,9 @@ describe('Anvil API Client', function () { describe('requestGraphQL', function () { beforeEach(function () { - sinon.stub(client, '_wrapRequest') + sandbox.stub(client, '_wrapRequest') client._wrapRequest.callsFake(async () => ({})) - sinon.stub(client, '_request') - }) - - afterEach(function () { - client._wrapRequest.restore() - client._request.restore() + sandbox.stub(client, '_request') }) describe('without files', function () { @@ -413,11 +414,7 @@ describe('Anvil API Client', function () { describe('with files', function () { beforeEach(function () { - sinon.spy(FormData.prototype, 'append') - }) - - afterEach(function () { - FormData.prototype.append.restore() + sandbox.spy(FormData.prototype, 'append') }) describe('schema is good', function () { @@ -526,11 +523,7 @@ describe('Anvil API Client', function () { describe('createEtchPacket', function () { beforeEach(function () { - sinon.stub(client, 'requestGraphQL') - }) - - afterEach(function () { - client.requestGraphQL.restore() + sandbox.stub(client, 'requestGraphQL') }) context('mutation is specified', function () { @@ -599,14 +592,11 @@ describe('Anvil API Client', function () { describe('generateEtchSignUrl', function () { def('statusCode', 200) beforeEach(async function () { - sinon.stub(client, '_request') + sandbox.stub(client, '_request') client._request.callsFake((url, options) => { return Promise.resolve($.nodeFetchResponse) }) }) - afterEach(function () { - client._request.restore() - }) context('everything goes well', function () { def('data', { @@ -650,11 +640,7 @@ describe('Anvil API Client', function () { describe('getEtchPacket', function () { def('variables', { eid: 'etchPacketEid123' }) beforeEach(function () { - sinon.stub(client, 'requestGraphQL') - }) - - afterEach(function () { - client.requestGraphQL.restore() + sandbox.stub(client, 'requestGraphQL') }) context('no responseQuery specified', function () { @@ -694,5 +680,29 @@ describe('Anvil API Client', function () { }) }) }) + + describe('getPDFInfo', function () { + def('variables', { castEid: 'castEidAbc123456' }) + + beforeEach(function () { + sandbox.stub(client, 'requestGraphQL') + }) + + it('called getPDFInfo', async function () { + client.getPDFInfo({ variables: $.variables }) + + expect(client.requestGraphQL).to.have.been.calledOnce + const [options, clientOptions] = client.requestGraphQL.lastCall.args + + const { + query, + variables: variablesReceived, + } = options + + expect($.variables).to.eql(variablesReceived) + expect(query).to.include('getPDFInfo (') + expect(clientOptions).to.eql({ dataType: 'json' }) + }) + }) }) }) From 2ba6e151c43c9b2b5827c907cdd87148fbbc41ed Mon Sep 17 00:00:00 2001 From: newhouse Date: Tue, 15 Dec 2020 18:20:58 -0800 Subject: [PATCH 3/3] doc update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7e6bcec..4cd26d8 100644 --- a/README.md +++ b/README.md @@ -207,7 +207,7 @@ Gets the details of a PDF. * `options` (Object) - An object with the following structure: * `variables` (Object) - An object with the following structure: * `castEid`: The EID of an existing Cast. - * `file`: Either a binary file (see [`prepareGraphQLFile`](#preparegraphqlfilepathorstreamlikething-options)) or a base64-encoded string in the same structure we support for the `createEtchPacket` mutation. See the [API Documentation](#api-documentation) for more. + * `file`: Either a binary file (see [`prepareGraphQLFile`](#preparegraphqlfilepathorstreamlikething-options)) or a base64-encoded string in the same structure we support for the `file` objects in the `createEtchPacket` mutation. See the [API Documentation](#api-documentation) for more. ##### generateEtchSignUrl(options)