From f15b02dca69dd487df241b36a50e6a06efbfb697 Mon Sep 17 00:00:00 2001 From: Sameena Shaffeeullah Date: Wed, 6 Oct 2021 13:18:44 -0700 Subject: [PATCH] fix: updated instance id to match returned metadata id (#696) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * deps: updated auth library version * fix: update id on object * revert auth library change * renamed test * 🦉 Updates from OwlBot See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md Co-authored-by: Owl Bot --- src/service-object.ts | 3 +++ test/service-object.ts | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/service-object.ts b/src/service-object.ts index 550d88e5..7da92b1d 100644 --- a/src/service-object.ts +++ b/src/service-object.ts @@ -250,6 +250,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/service-object.ts b/test/service-object.ts index eab42d7d..6cba89b0 100644 --- a/test/service-object.ts +++ b/test/service-object.ts @@ -175,6 +175,28 @@ describe('ServiceObject', () => { serviceObject.create(options, done); }); + it('should update id with metadata id', done => { + const config = extend({}, CONFIG, { + createMethod, + }); + const options = {}; + + function createMethod( + id: string, + options_: {}, + callback: (err: Error | null, a: {}, b: {}) => void + ) { + assert.strictEqual(id, config.id); + assert.strictEqual(options_, options); + callback(null, {metadata: {id: 14}}, {}); + } + + const serviceObject = new ServiceObject(config); + serviceObject.create(options); + assert.strictEqual(serviceObject.id, 14); + done(); + }); + it('should not require options', done => { const config = extend({}, CONFIG, { createMethod,