Skip to content

Commit d144d21

Browse files
authored
Merge pull request #20285 from bakulf/brandId
FXA-13359 - Add `brand_id` in the zendesk ticket creation request
2 parents f21207b + 4ffa0e6 commit d144d21

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

packages/fxa-auth-server/lib/routes/subscriptions/support.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,40 @@ describe('support', () => {
353353
})
354354
).rejects.toEqual(AppError.missingRequestParameter('email'));
355355
});
356+
357+
it('should submit a ticket with a valid brand_id', async () => {
358+
config.subscriptions.enabled = true;
359+
nock(`https://${SUBDOMAIN}.zendesk.com`)
360+
.post('/api/v2/requests.json')
361+
.reply(201, MOCK_CREATE_REPLY);
362+
nock(`https://${SUBDOMAIN}.zendesk.com`)
363+
.get(`/api/v2/users/${REQUESTER_ID}.json`)
364+
.reply(200, MOCK_EXISTING_SHOW_REPLY);
365+
const spy = sinon.spy(zendeskClient.requests, 'create');
366+
const res = await runTest('/support/ticket', {
367+
...requestOptions,
368+
payload: { ...requestOptions.payload, brand_id: 12345 },
369+
});
370+
const zendeskReq = spy.firstCall.args[0].request;
371+
expect(zendeskReq.brand_id).toBe(12345);
372+
expect(res).toEqual({ success: true, ticket: 91 });
373+
nock.isDone();
374+
spy.restore();
375+
});
376+
377+
it('should reject a ticket with a non-integer brand_id', async () => {
378+
config.subscriptions.enabled = true;
379+
const route = getRoute(
380+
supportRoutes(log, db, config, customs, zendeskClient),
381+
'/support/ticket',
382+
'POST'
383+
);
384+
const result = route.options.validate.payload.validate({
385+
...requestOptions.payload,
386+
brand_id: 12.5,
387+
});
388+
expect(result.error).toBeTruthy();
389+
});
356390
});
357391
});
358392
});

packages/fxa-auth-server/lib/routes/subscriptions/support.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export const supportRoutes = (
7373
message: isA.string().required(),
7474
product: isA.string().allow('').optional(),
7575
category: isA.string().allow('').optional(),
76+
brand_id: isA.number().integer().optional(),
7677
}) as any,
7778
},
7879
response: {
@@ -111,6 +112,7 @@ export const supportRoutes = (
111112
app,
112113
subject: payloadSubject,
113114
message,
115+
brand_id,
114116
} = request.payload;
115117
let subject = productName;
116118
if (payloadSubject) {
@@ -138,6 +140,7 @@ export const supportRoutes = (
138140
email,
139141
name: email,
140142
},
143+
...(brand_id !== undefined && { brand_id }),
141144
custom_fields: [
142145
{ id: productNameFieldId, value: productName },
143146
{ id: productFieldId, value: product },

0 commit comments

Comments
 (0)