1414
1515'use strict' ;
1616
17- const assert = require ( 'assert' ) ;
18- const execPromise = require ( 'child-process-promise' ) . exec ;
19- const path = require ( 'path' ) ;
20- const uuid = require ( 'uuid' ) ;
21- const sinon = require ( 'sinon' ) ;
22- const fetch = require ( 'node-fetch' ) ;
23- const waitPort = require ( 'wait-port' ) ;
24- const { Datastore} = require ( '@google-cloud/datastore' ) ;
17+ import { ok , strictEqual , deepStrictEqual } from 'assert' ;
18+ import { exec as execPromise } from 'child-process-promise' ;
19+ import { join } from 'path' ;
20+ import { v4 } from 'uuid' ;
21+ import { stub } from 'sinon' ;
22+ import fetch from 'node-fetch' ;
23+ import waitPort from 'wait-port' ;
24+ import { Datastore } from '@google-cloud/datastore' ;
2525
2626const datastore = new Datastore ( ) ;
27- const program = require ( '../' ) ;
27+ import { set , get , del } from '../' ;
2828
2929const FF_TIMEOUT = 3000 ;
30- const cwd = path . join ( __dirname , '..' ) ;
30+ const cwd = join ( __dirname , '..' ) ;
3131const NAME = 'sampletask1' ;
32- const KIND = `Task-${ uuid . v4 ( ) } ` ;
32+ const KIND = `Task-${ v4 ( ) } ` ;
3333const VALUE = {
3434 description : 'Buy milk' ,
3535} ;
@@ -72,14 +72,14 @@ describe('functions/datastore', () => {
7272 body : { } ,
7373 } ;
7474 const res = {
75- status : sinon . stub ( ) . returnsThis ( ) ,
76- send : sinon . stub ( ) ,
75+ status : stub ( ) . returnsThis ( ) ,
76+ send : stub ( ) ,
7777 } ;
7878
79- await program . set ( req , res ) ;
79+ await set ( req , res ) ;
8080
81- assert . ok ( res . status . calledWith ( 500 ) ) ;
82- assert . ok ( res . send . calledWith ( errorMsg ( 'Value' ) ) ) ;
81+ ok ( res . status . calledWith ( 500 ) ) ;
82+ ok ( res . send . calledWith ( errorMsg ( 'Value' ) ) ) ;
8383 } ) ;
8484
8585 it ( 'set: Fails without a key' , async ( ) => {
@@ -89,12 +89,12 @@ describe('functions/datastore', () => {
8989 } ,
9090 } ;
9191 const res = {
92- status : sinon . stub ( ) . returnsThis ( ) ,
93- send : sinon . stub ( ) ,
92+ status : stub ( ) . returnsThis ( ) ,
93+ send : stub ( ) ,
9494 } ;
95- await program . set ( req , res ) ;
96- assert . ok ( res . status . calledWith ( 500 ) ) ;
97- assert . ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
95+ await set ( req , res ) ;
96+ ok ( res . status . calledWith ( 500 ) ) ;
97+ ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
9898 } ) ;
9999
100100 it ( 'set: Fails without a kind' , async ( ) => {
@@ -105,14 +105,14 @@ describe('functions/datastore', () => {
105105 } ,
106106 } ;
107107 const res = {
108- status : sinon . stub ( ) . returnsThis ( ) ,
109- send : sinon . stub ( ) ,
108+ status : stub ( ) . returnsThis ( ) ,
109+ send : stub ( ) ,
110110 } ;
111111
112- await program . set ( req , res ) ;
112+ await set ( req , res ) ;
113113
114- assert . ok ( res . status . calledWith ( 500 ) ) ;
115- assert . ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
114+ ok ( res . status . calledWith ( 500 ) ) ;
115+ ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
116116 } ) ;
117117
118118 it ( 'set: Saves an entity' , async ( ) => {
@@ -125,9 +125,9 @@ describe('functions/datastore', () => {
125125 } ) ,
126126 headers : { 'Content-Type' : 'application/json' } ,
127127 } ) ;
128- assert . strictEqual ( response . status , 200 ) ;
128+ strictEqual ( response . status , 200 ) ;
129129 const body = await response . text ( ) ;
130- assert . ok ( body . includes ( `Entity ${ KIND } /${ NAME } saved` ) ) ;
130+ ok ( body . includes ( `Entity ${ KIND } /${ NAME } saved` ) ) ;
131131 } ) ;
132132 } ) ;
133133
@@ -159,9 +159,9 @@ describe('functions/datastore', () => {
159159 validateStatus : ( ) => true ,
160160 } ) ;
161161
162- assert . strictEqual ( response . status , 500 ) ;
162+ strictEqual ( response . status , 500 ) ;
163163 const body = await response . text ( ) ;
164- assert . ok (
164+ ok (
165165 new RegExp (
166166 / ( M i s s i n g o r i n s u f f i c i e n t p e r m i s s i o n s .) | ( N o e n t i t y f o u n d f o r k e y ) /
167167 ) . test ( body )
@@ -177,9 +177,9 @@ describe('functions/datastore', () => {
177177 } ) ,
178178 headers : { 'Content-Type' : 'application/json' } ,
179179 } ) ;
180- assert . strictEqual ( response . status , 200 ) ;
180+ strictEqual ( response . status , 200 ) ;
181181 const body = await response . json ( ) ;
182- assert . deepStrictEqual ( body , {
182+ deepStrictEqual ( body , {
183183 description : 'Buy milk' ,
184184 } ) ;
185185 } ) ;
@@ -189,14 +189,14 @@ describe('functions/datastore', () => {
189189 body : { } ,
190190 } ;
191191 const res = {
192- status : sinon . stub ( ) . returnsThis ( ) ,
193- send : sinon . stub ( ) ,
192+ status : stub ( ) . returnsThis ( ) ,
193+ send : stub ( ) ,
194194 } ;
195195
196- await program . get ( req , res ) ;
196+ await get ( req , res ) ;
197197
198- assert . ok ( res . status . calledWith ( 500 ) ) ;
199- assert . ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
198+ ok ( res . status . calledWith ( 500 ) ) ;
199+ ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
200200 } ) ;
201201
202202 it ( 'get: Fails without a kind' , async ( ) => {
@@ -206,14 +206,14 @@ describe('functions/datastore', () => {
206206 } ,
207207 } ;
208208 const res = {
209- status : sinon . stub ( ) . returnsThis ( ) ,
210- send : sinon . stub ( ) ,
209+ status : stub ( ) . returnsThis ( ) ,
210+ send : stub ( ) ,
211211 } ;
212212
213- await program . get ( req , res ) ;
213+ await get ( req , res ) ;
214214
215- assert . ok ( res . status . calledWith ( 500 ) ) ;
216- assert . ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
215+ ok ( res . status . calledWith ( 500 ) ) ;
216+ ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
217217 } ) ;
218218 } ) ;
219219
@@ -239,14 +239,14 @@ describe('functions/datastore', () => {
239239 body : { } ,
240240 } ;
241241 const res = {
242- status : sinon . stub ( ) . returnsThis ( ) ,
243- send : sinon . stub ( ) ,
242+ status : stub ( ) . returnsThis ( ) ,
243+ send : stub ( ) ,
244244 } ;
245245
246- await program . del ( req , res ) ;
246+ await del ( req , res ) ;
247247
248- assert . ok ( res . status . calledWith ( 500 ) ) ;
249- assert . ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
248+ ok ( res . status . calledWith ( 500 ) ) ;
249+ ok ( res . send . calledWith ( errorMsg ( 'Key' ) ) ) ;
250250 } ) ;
251251
252252 it ( 'del: Fails without a kind' , async ( ) => {
@@ -256,14 +256,14 @@ describe('functions/datastore', () => {
256256 } ,
257257 } ;
258258 const res = {
259- status : sinon . stub ( ) . returnsThis ( ) ,
260- send : sinon . stub ( ) ,
259+ status : stub ( ) . returnsThis ( ) ,
260+ send : stub ( ) ,
261261 } ;
262262
263- await program . del ( req , res ) ;
263+ await del ( req , res ) ;
264264
265- assert . ok ( res . status . calledWith ( 500 ) ) ;
266- assert . ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
265+ ok ( res . status . calledWith ( 500 ) ) ;
266+ ok ( res . send . calledWith ( errorMsg ( 'Kind' ) ) ) ;
267267 } ) ;
268268
269269 it ( "del: Doesn't fail when entity does not exist" , async ( ) => {
@@ -275,9 +275,9 @@ describe('functions/datastore', () => {
275275 } ) ,
276276 headers : { 'Content-Type' : 'application/json' } ,
277277 } ) ;
278- assert . strictEqual ( response . status , 200 ) ;
278+ strictEqual ( response . status , 200 ) ;
279279 const body = await response . text ( ) ;
280- assert . strictEqual ( body , `Entity ${ KIND } /nonexistent deleted.` ) ;
280+ strictEqual ( body , `Entity ${ KIND } /nonexistent deleted.` ) ;
281281 } ) ;
282282
283283 it ( 'del: Deletes an entity' , async ( ) => {
@@ -289,13 +289,13 @@ describe('functions/datastore', () => {
289289 } ) ,
290290 headers : { 'Content-Type' : 'application/json' } ,
291291 } ) ;
292- assert . strictEqual ( response . status , 200 ) ;
292+ strictEqual ( response . status , 200 ) ;
293293 const body = await response . text ( ) ;
294- assert . strictEqual ( body , `Entity ${ KIND } /${ NAME } deleted.` ) ;
294+ strictEqual ( body , `Entity ${ KIND } /${ NAME } deleted.` ) ;
295295
296296 const key = datastore . key ( [ KIND , NAME ] ) ;
297297 const [ entity ] = await datastore . get ( key ) ;
298- assert . ok ( ! entity ) ;
298+ ok ( ! entity ) ;
299299 } ) ;
300300 } ) ;
301301} ) ;
0 commit comments