-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add e2e tests for GET /api/v1/sessions/@this
- Loading branch information
Showing
10 changed files
with
169 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
repository_root := $(shell git rev-parse --show-toplevel) | ||
export repository_root := $(or $(repository_root), $(CURDIR)) | ||
include $(repository_root)/variables.mk | ||
|
||
export COMPOSE_PROJECT_NAME := prisme-bun-sessions | ||
|
||
.PHONY: start | ||
start: | ||
source $(CURDIR)/prisme.env && \ | ||
$(DOCKER_COMPOSE) \ | ||
-f ../docker-compose.yml \ | ||
-f ./docker-compose.env.yml \ | ||
up --wait -d | ||
|
||
.PHONY: test | ||
test: | ||
$(DOCKER_COMPOSE) \ | ||
-f ./docker-compose.test.yml \ | ||
up \ | ||
--abort-on-container-exit \ | ||
--exit-code-from bun | ||
|
||
.PHONY: clean | ||
clean: | ||
$(DOCKER_COMPOSE) \ | ||
-f ../docker-compose.yml \ | ||
-f ./docker-compose.env.yml \ | ||
-f ./docker-compose.test.yml \ | ||
down --volumes --remove-orphans |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
services: | ||
prisme: | ||
image: prismelabs/analytics:dev | ||
env_file: $PWD/prisme.env | ||
healthcheck: | ||
test: ["CMD", "/healthcheck"] | ||
networks: | ||
default: | ||
aliases: | ||
- prisme.localhost | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
services: | ||
bun: | ||
image: docker.io/oven/bun | ||
command: sh -c "bun install && cd ./sessions && exec bun test" | ||
working_dir: /data | ||
volumes: | ||
- ..:/data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
export PRISME_MODE="ingestion" | ||
|
||
export PRISME_CLICKHOUSE_HOSTPORT='clickhouse.localhost:9000' | ||
export PRISME_CLICKHOUSE_USER="clickhouse" | ||
export PRISME_CLICKHOUSE_PASSWORD="password" | ||
|
||
export PRISME_ORIGIN_REGISTRY_ORIGINS="mywebsite.localhost,foo.mywebsite.localhost" | ||
|
||
export PRISME_EVENTSTORE_MAX_BATCH_SIZE="1" | ||
|
||
# Trust proxy so we can change rate limited IP address using X-Forwarded-For | ||
export PRISME_TRUST_PROXY="true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { expect, test } from 'bun:test' | ||
import { faker } from '@faker-js/faker' | ||
import { PRISME_PAGEVIEWS_URL, PRISME_SESSIONS_THIS_URL, PRISME_VISITOR_ID_REGEX, UUID_V7_REGEX } from '../const' | ||
|
||
const seed = new Date().getTime() | ||
console.log('faker seed', seed) | ||
faker.seed(seed) | ||
|
||
test('', async () => { | ||
const ipAddr = '8.8.8.8' | ||
const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.3' | ||
// Create session. | ||
let response = await fetch(PRISME_PAGEVIEWS_URL, { | ||
method: 'POST', | ||
headers: { | ||
Origin: 'http://foo.mywebsite.localhost', | ||
'X-Forwarded-For': ipAddr, | ||
Referer: 'http://foo.mywebsite.localhost/?utm_source=my_utm_source', | ||
'X-Prisme-Document-Referrer': 'http://example.com/', | ||
'User-Agent': userAgent | ||
} | ||
}) | ||
expect(response.status).toBe(200) | ||
|
||
// Retrieve session. | ||
response = await fetch(PRISME_SESSIONS_THIS_URL, { | ||
method: 'POST', | ||
headers: { | ||
Origin: 'http://foo.mywebsite.localhost', | ||
'X-Forwarded-For': ipAddr, | ||
Referer: 'http://foo.mywebsite.localhost/', | ||
'User-Agent': userAgent | ||
} | ||
}) | ||
expect(response.status).toBe(200) | ||
|
||
let data = await response.json() | ||
const visitorId = data.VisitorId | ||
const sessionUuid = data.SessionUuid | ||
expect(data).toMatchObject({ | ||
Client: { | ||
OperatingSystem: 'Windows', | ||
BrowserFamily: 'Chrome', | ||
Device: 'Other', | ||
IsBot: false | ||
}, | ||
CountryCode: 'US', | ||
PageUri: 'http://foo.mywebsite.localhost/?utm_source=my_utm_source', | ||
PageviewCount: 1, | ||
ReferrerUri: 'http://example.com/', | ||
Utm: { | ||
Campaign: '', | ||
Content: '', | ||
Medium: '', | ||
Source: 'my_utm_source', | ||
Term: '' | ||
}, | ||
VisitorId: expect.stringMatching(PRISME_VISITOR_ID_REGEX), | ||
SessionUuid: expect.stringMatching(UUID_V7_REGEX) | ||
}) | ||
|
||
// Second page view. | ||
response = await fetch(PRISME_PAGEVIEWS_URL, { | ||
method: 'POST', | ||
headers: { | ||
Origin: 'http://foo.mywebsite.localhost', | ||
'X-Forwarded-For': ipAddr, | ||
'X-Prisme-Document-Referrer': 'http://foo.mywebsite.localhost/', | ||
Referer: 'http://foo.mywebsite.localhost/bar', | ||
'User-Agent': userAgent | ||
} | ||
}) | ||
expect(response.status).toBe(200) | ||
|
||
// Retrieve session. | ||
response = await fetch(PRISME_SESSIONS_THIS_URL, { | ||
method: 'POST', | ||
headers: { | ||
Origin: 'http://foo.mywebsite.localhost', | ||
'X-Forwarded-For': ipAddr, | ||
Referer: 'http://foo.mywebsite.localhost', | ||
'User-Agent': userAgent | ||
} | ||
}) | ||
expect(response.status).toBe(200) | ||
|
||
data = await response.json() | ||
expect(data).toMatchObject({ | ||
Client: { | ||
OperatingSystem: 'Windows', | ||
BrowserFamily: 'Chrome', | ||
Device: 'Other', | ||
IsBot: false | ||
}, | ||
CountryCode: 'US', | ||
PageUri: 'http://foo.mywebsite.localhost/?utm_source=my_utm_source', | ||
PageviewCount: 2, | ||
ReferrerUri: 'http://example.com/', | ||
Utm: { | ||
Campaign: '', | ||
Content: '', | ||
Medium: '', | ||
Source: 'my_utm_source', | ||
Term: '' | ||
}, | ||
VisitorId: visitorId, | ||
SessionUuid: sessionUuid | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters