Skip to content

Commit

Permalink
fix: deleting, getting, and getting metadata for notifications (#1872)
Browse files Browse the repository at this point in the history
* fix: deleting, getting, and getting metadata for notifications

* removed test added by bigquery when we first reverted this change
  • Loading branch information
shaffeeullah authored Apr 14, 2022
1 parent 640f7b0 commit 451570e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
5 changes: 4 additions & 1 deletion conformance-test/test-data/retryInvocationMap.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions src/nodejs-common/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,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
36 changes: 18 additions & 18 deletions test/nodejs-common/service-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down

0 comments on commit 451570e

Please sign in to comment.