Skip to content

Commit

Permalink
add new e2e test env for events endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
negrel committed Jan 23, 2024
1 parent 025b439 commit cb6369a
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 3 deletions.
2 changes: 1 addition & 1 deletion tests/bun/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.PHONY: all
all: all/default all/trusted-proxy all/untrusted-proxy
all: all/default all/events all/trusted-proxy all/untrusted-proxy
@true

all/%: start/% test/% clean/%
Expand Down
2 changes: 1 addition & 1 deletion tests/bun/default/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { expect, test } from 'bun:test'
import { PRISME_URL } from './utils'
import { PRISME_URL } from '../const'

test('anonymous request is redirected to /sign_in', async () => {
const response = await fetch(PRISME_URL, {
Expand Down
Empty file removed tests/bun/default/matchers.ts
Empty file.
1 change: 0 additions & 1 deletion tests/bun/default/prisme.env
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
export PRISME_POSTGRES_URL='postgres://postgres:[email protected]:5432/prisme?sslmode=disable'

export PRISME_CLICKHOUSE_HOSTPORT='clickhouse.localhost:9000'
export PRISME_CLICKHOUSE_DB="prisme"
export PRISME_CLICKHOUSE_USER="clickhouse"
export PRISME_CLICKHOUSE_PASSWORD="password"

Expand Down
29 changes: 29 additions & 0 deletions tests/bun/events/Makefile
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-events

.PHONY: start
start:
source $(CURDIR)/prisme.env && \
$(DOCKER_COMPOSE) \
-f $(repository_root)/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 $(repository_root)/docker-compose.yml \
-f ./docker-compose.env.yml \
-f ./docker-compose.test.yml \
down --volumes --remove-orphans
10 changes: 10 additions & 0 deletions tests/bun/events/docker-compose.env.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'
services:
prisme:
image: prismelabs/analytics:dev
env_file: $PWD/prisme.env
networks:
default:
aliases:
- prisme.localhost

8 changes: 8 additions & 0 deletions tests/bun/events/docker-compose.test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'
services:
bun:
image: docker.io/oven/bun
command: sh -c "bun install && cd ./events && exec bun test"
working_dir: /data
volumes:
- ..:/data
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { expect, test } from 'bun:test'
import { faker } from '@faker-js/faker'

import { createClient } from '@clickhouse/client-web'
import { PRISME_PAGEVIEWS_URL, TIMESTAMP_REGEX } from '../const'

const seed = new Date().getTime()
console.log('faker seed', seed)
faker.seed(seed)

test('GET request instead of POST request', async () => {
const response = await fetch(PRISME_PAGEVIEWS_URL)
expect(response.status).toBe(404)
Expand All @@ -11,6 +17,7 @@ test('invalid URL in X-Prisme-Referrer header', async () => {
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
'X-Prisme-Referrer': 'not an url'
}
})
Expand All @@ -21,6 +28,7 @@ test('invalid URL in Referer header', async () => {
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
Referer: 'not an url'
}
})
Expand All @@ -31,6 +39,7 @@ test('non registered domain in X-Prisme-Referrer header is rejected', async () =
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
'X-Prisme-Referrer': 'https://example.com/foo?bar=baz#qux'
}
})
Expand All @@ -41,6 +50,7 @@ test('non registered domain in Referer header is rejected', async () => {
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
Referer: 'https://example.com/foo?bar=baz#qux'
}
})
Expand All @@ -51,6 +61,7 @@ test('valid URL with registered domain in X-Prisme-Referrer header is accepted',
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
'X-Prisme-Referrer': 'http://mywebsite.localhost/foo?bar=baz#qux'
}
})
Expand Down Expand Up @@ -85,6 +96,7 @@ test('valid URL with registered domain in Referer header is accepted', async ()
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
Referer: 'http://foo.mywebsite.localhost/another/foo?bar=baz#qux'
}
})
Expand Down Expand Up @@ -119,6 +131,7 @@ test('valid pageview with Windows + Chrome user agent', async () => {
const response = await fetch(PRISME_PAGEVIEWS_URL, {
method: 'POST',
headers: {
'X-Forwarded-For': faker.internet.ip(),
Referer: 'http://foo.mywebsite.localhost/another/foo?bar=baz#qux',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.3'
}
Expand Down
12 changes: 12 additions & 0 deletions tests/bun/events/prisme.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export PRISME_POSTGRES_URL='postgres://postgres:[email protected]:5432/prisme?sslmode=disable'

export PRISME_CLICKHOUSE_HOSTPORT='clickhouse.localhost:9000'
export PRISME_CLICKHOUSE_USER="clickhouse"
export PRISME_CLICKHOUSE_PASSWORD="password"

export PRISME_SOURCE_REGISTRY_SOURCES="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"

0 comments on commit cb6369a

Please sign in to comment.