Skip to content

Commit

Permalink
fix: updated instance id to match returned metadata id (#696)
Browse files Browse the repository at this point in the history
* 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 <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
shaffeeullah and gcf-owl-bot[bot] authored Oct 6, 2021
1 parent d73448b commit f15b02d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ class ServiceObject<T = any> 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]));
Expand Down
22 changes: 22 additions & 0 deletions test/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f15b02d

Please sign in to comment.