diff --git a/conformance-test/test-data/retryInvocationMap.json b/conformance-test/test-data/retryInvocationMap.json index b3fb6af32..e92e7abd7 100644 --- a/conformance-test/test-data/retryInvocationMap.json +++ b/conformance-test/test-data/retryInvocationMap.json @@ -73,13 +73,16 @@ "createReadStream" ], "storage.notifications.delete": [ + "notificationDelete" ], "storage.notifications.insert": [ "createNotification", "notificationCreate" ], "storage.notifications.get": [ - "notificationExists" + "notificationExists", + "notificationGet", + "notificationGetMetadata" ], "storage.buckets.getIamPolicy": [ "iamGetPolicy" diff --git a/src/nodejs-common/service-object.ts b/src/nodejs-common/service-object.ts index bec9e1e74..af4d0434e 100644 --- a/src/nodejs-common/service-object.ts +++ b/src/nodejs-common/service-object.ts @@ -256,6 +256,9 @@ class ServiceObject extends EventEmitter { const [err, instance] = args; if (!err) { self.metadata = instance.metadata; + if (self.id && instance.metadata) { + self.id = instance.metadata.id; + } args[1] = self; // replace the created `instance` with this one. } callback!(...(args as {} as [Error, T])); diff --git a/test/nodejs-common/service-object.ts b/test/nodejs-common/service-object.ts index 0c143f200..518c08a5e 100644 --- a/test/nodejs-common/service-object.ts +++ b/test/nodejs-common/service-object.ts @@ -176,42 +176,42 @@ describe('ServiceObject', () => { serviceObject.create(options, done); }); - it('should not change id', done => { + it('should not require options', done => { const config = extend({}, CONFIG, { createMethod, }); - const options = {}; - function createMethod( - id: string, - options_: {}, - callback: (err: Error | null, a: {}, b: {}) => void - ) { + function createMethod(id: string, options: Function, callback: Function) { assert.strictEqual(id, config.id); - assert.strictEqual(options_, options); - callback(null, {metadata: {id: 14}}, {}); + assert.strictEqual(typeof options, 'function'); + assert.strictEqual(callback, undefined); + options(null, {}, {}); // calls done() } const serviceObject = new ServiceObject(config); - serviceObject.create(options); - assert.notStrictEqual(serviceObject.id, 14); - done(); + serviceObject.create(done); }); - it('should not require options', done => { + it('should update id with metadata id', done => { const config = extend({}, CONFIG, { createMethod, }); + const options = {}; - function createMethod(id: string, options: Function, callback: Function) { + function createMethod( + id: string, + options_: {}, + callback: (err: Error | null, a: {}, b: {}) => void + ) { assert.strictEqual(id, config.id); - assert.strictEqual(typeof options, 'function'); - assert.strictEqual(callback, undefined); - options(null, {}, {}); // calls done() + assert.strictEqual(options_, options); + callback(null, {metadata: {id: 14}}, {}); } const serviceObject = new ServiceObject(config); - serviceObject.create(done); + serviceObject.create(options); + assert.strictEqual(serviceObject.id, 14); + done(); }); it('should pass error to callback', done => {