Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(status): pin the text status length and colour rule

Yudhi Armyndharis5a2134073fae
diff --git a/src/modules/status/dto/send-text-status.dto.spec.ts b/src/modules/status/dto/send-text-status.dto.spec.ts
index 17dc1832d..3f6cc0d7e 100644
--- a/src/modules/status/dto/send-text-status.dto.spec.ts
+++ b/src/modules/status/dto/send-text-status.dto.spec.ts
@@ -80,4 +80,36 @@ describe('SendTextStatusDto text validation', () => {
it('accepts a body with surrounding whitespace', async () => {
expect(await validate(plainToInstance(SendTextStatusDto, { text: ' hi ' }))).toHaveLength(0);
});
+
+ // docs/06: text is at most 4096 characters.
+ it('accepts exactly 4096 characters and rejects 4097', async () => {
+ const failing = async (text: string): Promise<string[]> =>
+ (await validate(plainToInstance(SendTextStatusDto, { text }))).map(e => e.property);
+
+ expect(await failing('x'.repeat(4096))).toEqual([]);
+ expect(await failing('x'.repeat(4097))).toEqual(['text']);
+ });
+});
+
+// docs/06: backgroundColor is a 6-digit hex colour matching ^#[0-9A-Fa-f]{6}$. A short form, a missing
+// hash or a non-hex digit is refused rather than handed to the engine to draw as it sees fit.
+describe('SendTextStatusDto backgroundColor validation', () => {
+ const failing = async (backgroundColor: string): Promise<string[]> =>
+ (await validate(plainToInstance(SendTextStatusDto, { text: 'hi', backgroundColor }))).map(e => e.property);
+
+ it.each(['#25D366', '#25d366', '#000000', '#FFFFFF'])('accepts %s', async color => {
+ expect(await failing(color)).toEqual([]);
+ });
+
+ it.each([
+ ['the 3-digit short form', '#abc'],
+ ['5 digits', '#25D36'],
+ ['7 digits', '#25D3666'],
+ ['no hash', '25D366'],
+ ['a non-hex digit', '#25D36G'],
+ ['trailing whitespace', '#25D366 '],
+ ['an empty string', ''],
+ ])('rejects %s', async (_label, color) => {
+ expect(await failing(color)).toEqual(['backgroundColor']);
+ });
});