Skip to content

Commit

Permalink
fix e2e tests for multi sessions
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Oct 20, 2024
1 parent d343f05 commit 44c6ee9
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 73 deletions.
96 changes: 47 additions & 49 deletions tests/bun/events/events_customs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test('GET request instead of POST request', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/foo',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
}
// body: JSON.stringify({}) // GET request can't have body.
Expand Down Expand Up @@ -43,7 +43,7 @@ test('non registered domain in Origin header is rejected', async () => {
headers: {
Origin: 'https://example.com',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'https://example.com/foo?bar=baz#qux',
'X-Prisme-Referrer': 'https://example.com/',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
Expand All @@ -57,7 +57,7 @@ test('content type different than application/json is rejected', async () => {
headers: {
Origin: 'https://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'https://mywebsite.localhost/foo?bar=baz#qux',
'X-Prisme-Referrer': 'https://mywebsite.localhost/',
'Content-Type': 'text/plain'
},
body: 'abc'
Expand All @@ -72,7 +72,7 @@ test('invalid sessionless custom event', async () => {
Origin: 'http://mywebsite.localhost',
// No session associated with this ip.
'X-Forwarded-For': faker.internet.ip(),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
Expand All @@ -86,7 +86,7 @@ test('malformed json body', async () => {
headers: {
Origin: 'https://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'https://mywebsite.localhost/foo?bar=baz#qux',
'X-Prisme-Referrer': 'https://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: '{"foo": "bar and foo, "num": 100' // No closing brace.
Expand All @@ -113,7 +113,7 @@ test('concurrent pageview and custom events', async () => {
headers: {
Origin: 'https://mywebsite.localhost',
'X-Forwarded-For': ipAddr,
Referer: 'https://mywebsite.localhost/path',
Referer: 'https://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
Expand All @@ -125,7 +125,7 @@ test('concurrent pageview and custom events', async () => {
headers: {
Origin: 'https://mywebsite.localhost',
'X-Forwarded-For': ipAddr,
'X-Prisme-Referrer': 'https://mywebsite.localhost/path'
'X-Prisme-Referrer': 'https://mywebsite.localhost/'
}
})
]).then((results) => results.forEach((resp) => expect(resp.status).toBe(200)))
Expand All @@ -135,9 +135,9 @@ test('concurrent pageview and custom events', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -154,7 +154,7 @@ test('concurrent pageview and custom events', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/path',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -169,7 +169,7 @@ test('valid custom event request without body and Content-Type header', async ()
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html'
'X-Prisme-Referrer': 'http://mywebsite.localhost/'
// 'Content-Type': 'application/json' // not required if no body.
}
})
Expand All @@ -180,9 +180,9 @@ test('valid custom event request without body and Content-Type header', async ()
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -199,7 +199,7 @@ test('valid custom event request without body and Content-Type header', async ()
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -214,7 +214,7 @@ test('valid custom event with no properties', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
Expand All @@ -226,9 +226,9 @@ test('valid custom event with no properties', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -245,7 +245,7 @@ test('valid custom event with no properties', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -260,7 +260,7 @@ test('valid custom event with JSON bool as body', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify(true)
Expand All @@ -272,9 +272,9 @@ test('valid custom event with JSON bool as body', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -291,7 +291,7 @@ test('valid custom event with JSON bool as body', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -306,7 +306,7 @@ test('valid custom event with JSON number as body', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify(Math.random())
Expand All @@ -318,9 +318,9 @@ test('valid custom event with JSON number as body', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -337,7 +337,7 @@ test('valid custom event with JSON number as body', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -352,7 +352,7 @@ test('valid custom event with JSON string as body', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify(Math.random().toString())
Expand All @@ -364,9 +364,9 @@ test('valid custom event with JSON string as body', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -384,7 +384,7 @@ test('valid custom event with JSON string as body', async () => {
event: {
timestamp: expect.stringMatching(TIMESTAMP_REGEX),
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -403,7 +403,7 @@ test('valid custom event with few properties', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify(props)
Expand All @@ -415,9 +415,9 @@ test('valid custom event with few properties', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -434,7 +434,7 @@ test('valid custom event with few properties', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand Down Expand Up @@ -466,8 +466,7 @@ test('valid custom event with lot of properties', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
'X-Prisme-Referrer': 'http://mywebsite.localhost/index.html',
'X-Prisme-Document-Referrer': 'https://example.com/foo',
'X-Prisme-Referrer': 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify(props)
Expand All @@ -479,9 +478,9 @@ test('valid custom event with lot of properties', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -498,7 +497,7 @@ test('valid custom event with lot of properties', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -513,7 +512,7 @@ test('valid custom event without X-Prisme-Referrer', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost'),
Referer: 'http://mywebsite.localhost/index.html',
Referer: 'http://mywebsite.localhost/',
'Content-Type': 'application/json'
},
body: JSON.stringify({})
Expand All @@ -525,9 +524,9 @@ test('valid custom event without X-Prisme-Referrer', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand All @@ -544,7 +543,7 @@ test('valid custom event without X-Prisme-Referrer', async () => {
},
event: {
domain: 'mywebsite.localhost',
path: '/index.html',
path: '/',
visitor_id: expect.stringMatching(PRISME_VISITOR_ID_REGEX),
session_uuid: expect.stringMatching(UUID_V7_REGEX),
name: 'foo',
Expand All @@ -571,9 +570,9 @@ test('valid custom event without trailing slash in referrer', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Other',
browser_family: 'Other',
device: 'Other',
Expand Down Expand Up @@ -607,8 +606,7 @@ test('valid custom event with Windows + Chrome user agent', async () => {
headers: {
Origin: 'http://mywebsite.localhost',
'X-Forwarded-For': await randomIpWithSession('mywebsite.localhost', { userAgent }),
Referer: 'http://mywebsite.localhost',
'X-Prisme-Document-Referrer': 'https://www.example.com/foo',
Referer: 'http://mywebsite.localhost/',
'Content-Type': 'application/json',
'User-Agent': userAgent
},
Expand All @@ -621,9 +619,9 @@ test('valid custom event with Windows + Chrome user agent', async () => {
expect(data).toMatchObject({
session: {
domain: 'mywebsite.localhost',
entry_path: '/path',
entry_path: '/',
exit_timestamp: expect.stringMatching(TIMESTAMP_REGEX),
exit_path: '/path',
exit_path: '/',
operating_system: 'Windows',
browser_family: 'Chrome',
device: 'Other',
Expand Down
Loading

0 comments on commit 44c6ee9

Please sign in to comment.