Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: deleting, getting, and getting metadata for notifications #1872

Merged
merged 2 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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