Skip to content

Commit

Permalink
test(braze): testing the ins and out of digest
Browse files Browse the repository at this point in the history
  • Loading branch information
bassrock committed Aug 29, 2024
1 parent 4bf252e commit 553a0c1
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 0 deletions.
1 change: 1 addition & 0 deletions servers/braze-content-proxy/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ module.exports = {
testPathIgnorePatterns: ['/dist/', '/lambda/'],
testTimeout: 10000,
displayName: 'braze-content-proxy',
setupFiles: ['./jest.setup.js'],
setupFilesAfterEnv: ['jest-extended/all'],
};
10 changes: 10 additions & 0 deletions servers/braze-content-proxy/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
process.env.CHARACTER_MAP =
'[["A",0],["B",0],["C",0],["D",0],["E",0],["y",0],["F",1],["G",1],["H",1],["I",1],["J",1],["z",1],["K",2],["L",2],["M",2],["N",2],["O",2],["P",3],["Q",3],["R",3],["S",3],["T",3],["U",4],["V",4],["W",4],["X",4],["Y",4],["Z",5],["a",5],["b",5],["c",5],["d",5],["e",6],["f",6],["g",6],["h",6],["i",6],["j",7],["k",7],["l",7],["m",7],["n",7],["o",8],["p",8],["q",8],["r",8],["s",8],["t",9],["u",9],["v",9],["w",9],["x",9]]';
process.env.POSITION_MAP =
'[[9,0],[12,1],[26,2],[59,3],[45,4],[56,5],[23,6],[42,7],[48,8],[18,9],[40,10],[10,11],[37,12],[32,13],[21,14],[16,15]]';
process.env.MD5_RANDOMIZER =
'[["0",["g"]],["1",["g"]],["2",["h"]],["3",["a"]],["4",["a"]],["5",["3"]],["6",["1"]],["7",["1"]],["8",["7"]],["9",["k"]],["a",["v"]],["b",["X"]],["c",["i"]],["d",["f","T","q"]],["e",["o"]],["f",["O","h","b"]]]';
process.env.LETTER_INDEX =
'[["a",0],["b",1],["c",2],["d",3],["e",4],["f",5],["0",6]]';
process.env.SALT_1 = '123asdf';
process.env.SALT_2 = 'asdaa47';
104 changes: 104 additions & 0 deletions servers/braze-content-proxy/src/routes/digest.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,96 @@ import request from 'supertest';
import { Server } from 'http';
import { Application } from 'express';
import { startServer } from '../server';
import nock, { cleanAll, restore } from 'nock';
import { UserDigestQuery } from '../generated/graphql/types';
import { ApolloQueryResult } from '@apollo/client/core';

describe(`get digest`, () => {
let app: Application;
let server: Server;

const testEncodedUserId =
'fb792e6e9DE6E3ecI3Ca1CaE49A08497Bc36eA3eD5AacCd0Ba3b1056DbaB89d5';
const validUrl = `/digest/${testEncodedUserId}?apikey=${config.aws.brazeApiKey}`;

const fakeResponse: Omit<
ApolloQueryResult<UserDigestQuery>,
'loading' | 'networkStatus'
> = {
data: {
user: {
savedItems: {
edges: [
{
node: {
item: {
__typename: 'Item',
preview: {
title: 'Cool Item 1',
url: 'https://www.item1.com',
image: {
cachedImages: [
{
id: 'thumbnail',
url: 'https://image1.com',
},
],
},
},
},
},
},
{
node: {
item: {
__typename: 'Item',
preview: {
title: '',
url: 'https://item2.com',
image: null,
},
},
},
},
{
node: {
item: {
__typename: 'Item',
preview: {
title: 'Super Secret',
url: 'https://item3.com',
image: {
cachedImages: [
{
id: 'thumbnail',
url: 'image2.com',
},
],
},
},
},
},
},
{
node: {
item: {
__typename: 'PendingItem',
},
},
},
],
},
},
},
};

beforeAll(async () => {
({ app, server } = await startServer(0));
});
afterAll(async () => {
server.close();
cleanAll();
restore();
});
beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -26,4 +106,28 @@ describe(`get digest`, () => {
expect(response.body.error).not.toBeUndefined();
expect(response.body.error).toBe(config.app.INVALID_API_KEY_ERROR_MESSAGE);
});

it('should return correct data when valid query params are provided', async () => {
nock(config.clientApi.uri).post('/').reply(200, fakeResponse);

const response = await request(app).get(validUrl);

expect(response.statusCode).toBe(200);
expect(response.body).toEqual([
{
imageUrl: 'https://image1.com',
title: 'Cool Item 1',
url: 'https://www.item1.com',
},
{
title: '',
url: 'https://item2.com',
},
{
imageUrl: 'image2.com',
title: 'Super Secret',
url: 'https://item3.com',
},
]);
});
});

0 comments on commit 553a0c1

Please sign in to comment.