Skip to content

Commit

Permalink
fix: update masks for topic should be snake case (#1778)
Browse files Browse the repository at this point in the history
* fix: update masks for topic should be snake case

* fix: go back to lodash, and add tests

* chore: formatting
  • Loading branch information
feywind committed Jul 26, 2023
1 parent 6211c2f commit ba72638
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import {
SubscriptionOptions,
} from './subscription';
import {promisifySome} from './util';
import snakeCase = require('lodash.snakecase');

export type TopicMetadata = google.pubsub.v1.ITopic;

Expand Down Expand Up @@ -951,7 +952,7 @@ export class Topic {
callback = typeof optsOrCallback === 'function' ? optsOrCallback : callback;

const topic = Object.assign({name: this.name}, options);
const updateMask = {paths: Object.keys(options)};
const updateMask = {paths: Object.keys(options).map(snakeCase)};
const reqOpts = {topic, updateMask};

this.request<TopicMetadata>(
Expand Down
16 changes: 16 additions & 0 deletions system-test/pubsub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,22 @@ describe('pubsub', () => {
);
});

it('should set metadata for a topic', async () => {
const threeDaysInSeconds = 3 * 24 * 60 * 60;

const topic = pubsub.topic(TOPIC_NAMES[0]);
await topic.setMetadata({
messageRetentionDuration: {
seconds: threeDaysInSeconds,
},
});
const [metadata] = await topic.getMetadata();
const {seconds, nanos} = metadata.messageRetentionDuration!;

assert.strictEqual(Number(seconds), threeDaysInSeconds);
assert.strictEqual(Number(nanos), 0);
});

describe('ordered messages', () => {
interface Expected {
key: string;
Expand Down
5 changes: 4 additions & 1 deletion test/topic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,7 @@ describe('Topic', () => {
describe('setMetadata', () => {
const METADATA = {
labels: {yee: 'haw'},
messageRetentionDuration: {moo: 'cows'},
};

let requestStub: sinon.SinonStub;
Expand All @@ -691,7 +692,9 @@ describe('Topic', () => {
topic.setMetadata(METADATA, assert.ifError);

const expectedTopic = Object.assign({name: topic.name}, METADATA);
const expectedUpdateMask = {paths: ['labels']};
const expectedUpdateMask = {
paths: ['labels', 'message_retention_duration'],
};

const [{reqOpts}] = requestStub.lastCall.args;
assert.deepStrictEqual(reqOpts.topic, expectedTopic);
Expand Down

0 comments on commit ba72638

Please sign in to comment.