Skip to content
This repository has been archived by the owner on Jul 20, 2023. It is now read-only.

Commit

Permalink
feat: additional helpers test
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwlui committed Jul 17, 2018
1 parent 37c5112 commit 5b9a427
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,5 +478,47 @@ describe('Vision helper methods', () => {
assert(ex.message.indexOf('Setting explicit') > -1);
});
});

it('creates and promisify methods that are available in certain versions', () => {
const client = new vision.v1p3beta1.ImageAnnotatorClient();
let request = {
image: {source: {imageUri: 'https://cloud.google.com/vision/docs/images/bicycle.jpg'}},
};
let batchAnnotate = sandbox.stub(client, 'batchAnnotateImages');
batchAnnotate.callsArgWith(2, undefined, {
responses: [
{
localizedObjectAnnotations: [{dummy: 'response'}],
},
],
});

client
.productSearch(request)
.then(r => {
let response = r[0];

assert.deepEqual(response, {
localizedObjectAnnotations: [{dummy: 'response'}],
});

assert(batchAnnotate.callCount === 1);
assert(batchAnnotate.calledWith({requests: [request]}));
})
.catch(assert.ifError);
});

it('throws an error if trying to invoke a method not available in current version', () => {
// Use v1 version of client.
const client = new vision.v1.ImageAnnotatorClient(CREDENTIALS);

assert.throws(
() => {
// Object localization is only available for v1p3beta1.
client.objectLocalization({})
},
'TypeError: client.objectLocalization is not a function',
);
})
});
});

0 comments on commit 5b9a427

Please sign in to comment.