16
16
'use strict' ;
17
17
18
18
const path = require ( `path` ) ;
19
+ const uuid = require ( `uuid` ) ;
19
20
const vision = require ( '@google-cloud/vision' ) . v1p3beta1 ;
20
21
const productSearchClient = new vision . ProductSearchClient ( ) ;
21
22
const assert = require ( 'assert' ) ;
22
23
const tools = require ( `@google-cloud/nodejs-repo-tools` ) ;
23
24
const cmd = `node productSearch.v1p3beta1.js` ;
24
- const cwd = path . join ( __dirname , `..` ) ;
25
+ const cwd = path . join ( __dirname , `..` , `productSearch` ) ;
25
26
26
27
// Shared fixture data for product tests
27
28
const testProductSet = {
28
29
projectId : process . env . GCLOUD_PROJECT ,
29
30
location : 'us-west1' ,
30
31
productCategory : 'homegoods' ,
31
- productId : 'test_product_id_1' ,
32
- productSetId : 'test_product_set_id_1' ,
32
+ productId : `test_product_id${ uuid . v4 ( ) } ` ,
33
+ productDisplayName : 'test_product_display_name_1' ,
34
+ productSetId : `test_product_set_id${ uuid . v4 ( ) } ` ,
33
35
productSetDisplayName : 'test_product_set_display_name_1' ,
34
36
} ;
35
37
@@ -47,43 +49,43 @@ describe(`product search`, () => {
47
49
48
50
before ( async ( ) => {
49
51
// Create a test product set for each test
50
- try {
51
- await productSearchClient . createProduct ( {
52
- parent : productSearchClient . locationPath (
53
- testProductSet . projectId ,
54
- testProductSet . location
55
- ) ,
56
- productId : testProductSet . productId ,
57
- product : {
58
- displayName : testProductSet . productDisplayName ,
59
- productCategory : testProductSet . productCategory ,
60
- } ,
61
- } ) ;
62
- testProductSet . createdProductPaths . push ( testProductSet . productPath ) ;
63
- } catch ( err ) { } // ignore error
52
+ await productSearchClient . createProduct ( {
53
+ parent : productSearchClient . locationPath (
54
+ testProductSet . projectId ,
55
+ testProductSet . location
56
+ ) ,
57
+ productId : testProductSet . productId ,
58
+ product : {
59
+ displayName : testProductSet . productDisplayName ,
60
+ productCategory : testProductSet . productCategory ,
61
+ } ,
62
+ } ) ;
63
+ testProductSet . createdProductPaths . push ( testProductSet . productPath ) ;
64
64
65
- try {
66
- await productSearchClient . createProductSet ( {
67
- parent : productSearchClient . locationPath (
68
- testProductSet . projectId ,
69
- testProductSet . location
70
- ) ,
71
- productSetId : testProductSet . productSetId ,
72
- productSet : {
73
- displayName : testProductSet . productSetDisplayName ,
74
- } ,
75
- } ) ;
76
- testProductSet . createdProductSetPaths . push (
77
- testProductSet . createdProductSetPaths
78
- ) ;
79
- } catch ( err ) { } // ignore error
65
+ await productSearchClient . createProductSet ( {
66
+ parent : productSearchClient . locationPath (
67
+ testProductSet . projectId ,
68
+ testProductSet . location
69
+ ) ,
70
+ productSetId : testProductSet . productSetId ,
71
+ productSet : {
72
+ displayName : testProductSet . productSetDisplayName ,
73
+ } ,
74
+ } ) ;
75
+ testProductSet . createdProductSetPaths . push (
76
+ testProductSet . createdProductSetPaths
77
+ ) ;
80
78
} ) ;
81
79
82
80
after ( async ( ) => {
83
81
// Delete products sets after each test
84
82
testProductSet . createdProductSetPaths . forEach ( async path => {
85
83
try {
86
84
await productSearchClient . deleteProductSet ( { name : path } ) ;
85
+ } catch ( err ) { } // ignore error
86
+ } ) ;
87
+ testProductSet . createdProductPaths . forEach ( async path => {
88
+ try {
87
89
await productSearchClient . deleteProduct ( { name : path } ) ;
88
90
} catch ( err ) { } // ignore error
89
91
} ) ;
@@ -100,18 +102,14 @@ describe(`product search`, () => {
100
102
assert . ok ( output . includes ( `Product added to product set.` ) ) ;
101
103
} ) ;
102
104
103
- test ( ` remove a product from a product set`, async ( ) => {
105
+ it ( `should remove a product from a product set`, async ( ) => {
104
106
const output = await tools . runAsync (
105
107
`${ cmd } removeProductFromProductSet "${ testProductSet . projectId } " "${
106
108
testProductSet . location
107
109
} " "${ testProductSet . productId } " "${ testProductSet . productSetId } "`,
108
110
cwd
109
111
) ;
110
112
111
- console . log ( '---------------' ) ;
112
- console . log ( output ) ;
113
- console . log ( '---------------' ) ;
114
-
115
113
assert . ok ( output . includes ( `Product removed from product set.` ) ) ;
116
114
} ) ;
117
115
} ) ;
0 commit comments