Skip to content

Commit 34fbcd6

Browse files
authored
fix: To strict validation. (#31)
Attributes are not required, so it shouldn't fail if it's not set. Also adds a test to ensure this.
1 parent f50eddc commit 34fbcd6

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

src/__tests__/fastify-plugin.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,25 @@ describe('fastify-plugin', () => {
8989
`"{\\"statusCode\\":500,\\"error\\":\\"Internal Server Error\\",\\"message\\":\\"error\\"}"`,
9090
);
9191
});
92+
93+
it('should not throw if request is missing attributes', async () => {
94+
const handler = jest.fn();
95+
const payload = {
96+
message: {
97+
data: 'ImZvcndhcmQgbWUi',
98+
messageId: 'in dolor Ut',
99+
},
100+
subscription: 'mollit sint',
101+
};
102+
103+
app.register(pubSubFastifyPlugin, { handler });
104+
105+
const res = await app.inject({
106+
method: 'POST',
107+
url: '/',
108+
payload,
109+
});
110+
111+
expect(res.statusCode).toBe(204);
112+
});
92113
});

src/__tests__/index.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ describe('index', () => {
1414
"type": "string",
1515
},
1616
"kind": Symbol(DictKind),
17+
"modifier": Symbol(OptionalModifier),
1718
"type": "object",
1819
},
1920
"data": Object {
@@ -27,7 +28,6 @@ describe('index', () => {
2728
},
2829
},
2930
"required": Array [
30-
"attributes",
3131
"data",
3232
],
3333
"type": "object",
@@ -44,6 +44,7 @@ describe('index', () => {
4444
"type": "string",
4545
},
4646
"kind": Symbol(DictKind),
47+
"modifier": Symbol(OptionalModifier),
4748
"type": "object",
4849
},
4950
"data": Object {
@@ -57,7 +58,6 @@ describe('index', () => {
5758
},
5859
},
5960
"required": Array [
60-
"attributes",
6161
"data",
6262
],
6363
"type": "object",

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export interface PubSubConfig {
2727
}
2828

2929
export const PubSubMessage = Type.Object({
30-
attributes: Type.Dict(Type.String()),
30+
attributes: Type.Optional(Type.Dict(Type.String())),
3131
data: Type.String(),
3232
messageId: Type.Optional(Type.String()),
3333
});

0 commit comments

Comments
 (0)