Skip to content

Commit 6597ab6

Browse files
stephenplusplussofisl
authored andcommitted
bigquery/language/logging/prediction/vision: decouple packages (#1531)
* bigquery/language/logging/prediction/vision: decouple packages * tests: allow more time for docs tests to run * add vision test * resort dependencies like npm does
1 parent 67bab24 commit 6597ab6

File tree

3 files changed

+30
-11
lines changed

3 files changed

+30
-11
lines changed

packages/google-cloud-language/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@
5252
"language"
5353
],
5454
"dependencies": {
55-
"@google-cloud/common": "^0.1.0",
56-
"@google-cloud/storage": "^0.1.0",
55+
"@google-cloud/common": "^0.3.0",
5756
"arguejs": "^0.2.3",
5857
"arrify": "^1.0.1",
5958
"extend": "^3.0.0",
@@ -64,6 +63,7 @@
6463
"string-format-obj": "^1.0.0"
6564
},
6665
"devDependencies": {
66+
"@google-cloud/storage": "*",
6767
"mocha": "^2.1.0",
6868
"node-uuid": "^1.4.7",
6969
"proxyquire": "^1.7.10",

packages/google-cloud-language/src/document.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
'use strict';
2222

2323
var arrify = require('arrify');
24+
var common = require('@google-cloud/common');
2425
var extend = require('extend');
25-
var File = require('@google-cloud/storage').File;
2626
var format = require('string-format-obj');
2727
var is = require('is');
2828
var prop = require('propprop');
@@ -76,7 +76,7 @@ function Document(language, config) {
7676
this.reqOpts.document.type = 'PLAIN_TEXT';
7777
}
7878

79-
if (content instanceof File) {
79+
if (common.util.isCustomType(content, 'storage/file')) {
8080
this.reqOpts.document.gcsContentUri = format('gs://{bucket}/{file}', {
8181
bucket: encodeURIComponent(content.bucket.id),
8282
file: encodeURIComponent(content.id)

packages/google-cloud-language/test/document.js

+26-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,16 @@ var prop = require('propprop');
2222
var proxyquire = require('proxyquire');
2323
var util = require('@google-cloud/common').util;
2424

25-
function FakeFile() {}
25+
var isCustomTypeOverride;
26+
var fakeUtil = extend(true, {}, util, {
27+
isCustomType: function() {
28+
if (isCustomTypeOverride) {
29+
return isCustomTypeOverride.apply(null, arguments);
30+
}
31+
32+
return false;
33+
}
34+
});
2635

2736
describe('Document', function() {
2837
var DocumentCache;
@@ -36,15 +45,17 @@ describe('Document', function() {
3645

3746
before(function() {
3847
Document = proxyquire('../src/document.js', {
39-
'@google-cloud/storage': {
40-
File: FakeFile
48+
'@google-cloud/common': {
49+
util: fakeUtil
4150
}
4251
});
4352

4453
DocumentCache = extend(true, {}, Document);
4554
});
4655

4756
beforeEach(function() {
57+
isCustomTypeOverride = null;
58+
4859
for (var property in DocumentCache) {
4960
if (DocumentCache.hasOwnProperty(property)) {
5061
Document[property] = DocumentCache[property];
@@ -123,11 +134,19 @@ describe('Document', function() {
123134
});
124135

125136
it('should set the GCS content URI from a File', function() {
126-
var file = new FakeFile();
137+
var file = {
138+
// Leave spaces in to check that it is URI-encoded:
139+
id: 'file name',
140+
bucket: {
141+
id: 'bucket name'
142+
}
143+
};
127144

128-
// Leave spaces in to check that it is URI-encoded:
129-
file.bucket = { id: 'bucket id' };
130-
file.id = 'file name';
145+
isCustomTypeOverride = function(content, type) {
146+
assert.strictEqual(content, file);
147+
assert.strictEqual(type, 'storage/file');
148+
return true;
149+
};
131150

132151
var document = new Document(LANGUAGE, {
133152
content: file

0 commit comments

Comments
 (0)