Skip to content

getPDFInfo #35

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `file` objects in 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.
Expand Down
13 changes: 13 additions & 0 deletions src/graphql/queries/getPDFInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
generateQuery: () => `
query GetPDFInfo (
$castEid: String,
$file: Upload,
) {
getPDFInfo (
castEid: $castEid,
file: $file,
)
}
`,
}
13 changes: 13 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ const {
etchPacket: {
generateQuery: generateEtchPacketQuery,
},
getPDFInfo: {
generateQuery: generateGetPDFInfoQuery,
},
},
} = require('./graphql')

Expand Down Expand Up @@ -136,6 +139,16 @@ class Anvil {
)
}

getPDFInfo ({ variables }) {
return this.requestGraphQL(
{
query: generateGetPDFInfoQuery(),
variables,
},
{ dataType: DATA_TYPE_JSON },
)
}

createEtchPacket ({ variables, responseQuery, mutation }) {
return this.requestGraphQL(
{
Expand Down
64 changes: 37 additions & 27 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -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 () {
Expand Down Expand Up @@ -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' })
})
})
})
})