From 5656a09493485c4a6d03e818bac9a2c37e1f03e8 Mon Sep 17 00:00:00 2001 From: Kat Schelonka Date: Tue, 28 Jan 2025 09:30:38 -0800 Subject: [PATCH] fix(v3proxy): add send_guid endpoint Routes to v3/send controller. For backwards-compatible Android requests, which are erroring out due to 404 when accessing Home while not logged in. This endpoint is just legacy analytics, so we will ignore the actions in the same way that we ignore them in v3/send (by returning false and an error in the response, but not a failure of the entire request. [POCkET-10932] --- .../src/routes/v3SendGuid.integration.ts | 48 +++++++++++++++++++ servers/v3-proxy-api/src/server.ts | 1 + 2 files changed, 49 insertions(+) create mode 100644 servers/v3-proxy-api/src/routes/v3SendGuid.integration.ts diff --git a/servers/v3-proxy-api/src/routes/v3SendGuid.integration.ts b/servers/v3-proxy-api/src/routes/v3SendGuid.integration.ts new file mode 100644 index 000000000..4b9fd8108 --- /dev/null +++ b/servers/v3-proxy-api/src/routes/v3SendGuid.integration.ts @@ -0,0 +1,48 @@ +import request from 'supertest'; +import { startServer } from '../server'; +import { Server } from 'http'; +import { Application } from 'express'; +import { GraphQLClient } from 'graphql-request'; + +describe('v3/send_guid', () => { + let app: Application; + let server: Server; + let clientSpy; + + beforeAll(async () => { + ({ app, server } = await startServer(0)); + // Response is unused so it doesn't matter what it returns + clientSpy = jest + .spyOn(GraphQLClient.prototype, 'request') + .mockResolvedValue(true); + }); + afterAll(async () => { + clientSpy.mockRestore(); + server.close(); + jest.restoreAllMocks(); + }); + afterEach(() => jest.clearAllMocks()); + + it('Accepts actions without access token on POST', async () => { + const actions = + '%5B%7B%22action_identifier%22%3A%22referrer%22%2C%22page%22%3A%22installation%22%2C%22page_params%22%3A%22utm_source%3Dgoogle-play%26utm_medium%3Dorganic%22%2C%22section%22%3A%22core%22%2C%22time%22%3A1737985217%2C%22type_id%22%3A3%2C%22view%22%3A%22mobile%22%2C%22action%22%3A%22pv_wt%22%2C%22cxt_online%22%3A2%2C%22cxt_orient%22%3A1%2C%22sid%22%3A%221737985217%22%7D%5D'; + const response = await request(app).post('/v3/send_guid').send({ + consumer_key: 'test', + guid: 'test', + locale_lang: 'en-US', + actions, + }); + const expected = { + status: 1, + action_results: [false], + action_errors: [ + { + message: "Invalid Action: 'pv_wt'", + type: 'Bad request', + code: 130, + }, + ], + }; + expect(response.body).toEqual(expected); + }); +}); diff --git a/servers/v3-proxy-api/src/server.ts b/servers/v3-proxy-api/src/server.ts index b7288c039..485d65896 100644 --- a/servers/v3-proxy-api/src/server.ts +++ b/servers/v3-proxy-api/src/server.ts @@ -52,6 +52,7 @@ export async function startServer(port: number): Promise<{ app.use('/v3/add', v3AddRouter); app.use('/v3/fetch', v3FetchRouter); app.use('/v3/send', v3SendRouter); + app.use('/v3/send_guid', v3SendRouter); // NOTE: we on purpose do not setup the sentry middleware in this service since it is a proxy and we log our own errors.