Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
frankh committed Aug 13, 2024
1 parent 3e4eb29 commit 659b8d9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions functional_tests/mock-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ResponseComposition, rest } from 'msw'
import { setupServer } from 'msw/lib/node'
import { RestContext } from 'msw'
import { RestRequest } from 'msw'
import { decompressSync, strFromU8 } from 'fflate'

// the request bodies in a store that we can inspect within tests.
const capturedRequests: { '/e/': any[]; '/engage/': any[]; '/decide/': any[] } = {
Expand All @@ -18,8 +19,14 @@ const handleRequest = (group: string) => (req: RestRequest, res: ResponseComposi
if (typeof body === 'string') {
try {
const b64Encoded = req.url.href.includes('compression=base64')
const gzipCompressed = req.url.href.includes('compression=gzip-js')
if (b64Encoded) {
body = JSON.parse(Buffer.from(decodeURIComponent(body.split('=')[1]), 'base64').toString())
} else if (gzipCompressed) {
const data = new Uint8Array(req._body)
const decoded = strFromU8(decompressSync(data))
console.log(decoded)
body = JSON.parse(decoded)
} else {
body = JSON.parse(decodeURIComponent(body.split('=')[1]))
}
Expand Down

0 comments on commit 659b8d9

Please sign in to comment.