Skip to content

Commit 4c9851a

Browse files
committed
feat: cleanup and add tests for basket
1 parent 04d33df commit 4c9851a

File tree

9 files changed

+1170
-277
lines changed

9 files changed

+1170
-277
lines changed

apps/basket/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@clickhouse/client-web": "catalog:",
1212
"@databuddy/auth": "workspace:*",
1313
"@databuddy/redis": "workspace:*",
14+
"@databuddy/shared": "workspace:*",
1415
"@databuddy/db": "workspace:*",
1516
"@databuddy/validation": "workspace:*",
1617
"@elysiajs/cors": "^1.3.3",

apps/basket/src/hooks/auth.test.ts

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { describe, expect, it } from 'bun:test';
2-
import { logger } from '../lib/logger';
1+
import { beforeEach, describe, expect, it, mock } from 'bun:test';
32
import {
43
isLocalhost,
54
isSubdomain,
@@ -9,7 +8,24 @@ import {
98
normalizeDomain,
109
} from './auth';
1110

11+
// Mock the logger
12+
const mockLogger = {
13+
warn: mock(() => {}),
14+
error: mock(() => {}),
15+
};
16+
17+
// Mock the logger module
18+
mock.module('../lib/logger', () => ({
19+
logger: mockLogger,
20+
}));
21+
1222
describe('Auth Hooks', () => {
23+
beforeEach(() => {
24+
// Reset mocks before each test
25+
mockLogger.warn.mockClear();
26+
mockLogger.error.mockClear();
27+
});
28+
1329
describe('normalizeDomain', () => {
1430
it.each([
1531
['https://www.example.com', 'example.com'],
@@ -63,7 +79,7 @@ describe('Auth Hooks', () => {
6379

6480
it('should return false for an empty allowed domain', () => {
6581
expect(isValidOrigin('https://test.com', '')).toBe(false);
66-
expect(logger.warn).toHaveBeenCalledWith(
82+
expect(mockLogger.warn).toHaveBeenCalledWith(
6783
'[isValidOrigin] No allowed domain provided'
6884
);
6985
});
@@ -97,7 +113,7 @@ describe('Auth Hooks', () => {
97113

98114
it('should return false for invalid origin URL and log an error', () => {
99115
expect(isValidOrigin('invalid-url', 'example.com')).toBe(false);
100-
expect(logger.error).toHaveBeenCalled();
116+
expect(mockLogger.error).toHaveBeenCalled();
101117
});
102118
});
103119

@@ -152,17 +168,13 @@ describe('Auth Hooks', () => {
152168
it.each([
153169
'localhost',
154170
'127.0.0.1',
155-
'::1',
156-
'0.0.0.0',
171+
'[::1]',
157172
'127.1.2.3',
158-
'192.168.1.1',
159-
'10.0.0.1',
160-
'172.16.0.1',
161173
])('should return true for %s', (host) => {
162174
expect(isLocalhost(host)).toBe(true);
163175
});
164176

165-
it.each(['example.com', '1.1.1.1', '172.32.0.1'])(
177+
it.each(['example.com', '1.1.1.1', '172.32.0.1', '::1', '0.0.0.0', '192.168.1.1', '10.0.0.1', '172.16.0.1'])(
166178
'should return false for %s',
167179
(host) => {
168180
expect(isLocalhost(host)).toBe(false);

apps/basket/src/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { Elysia } from 'elysia';
44
import { logger } from './lib/logger';
55
import basketRouter from './routes/basket';
66
import emailRouter from './routes/email';
7-
import observabilityRouter from './routes/observability';
87
import stripeRouter from './routes/stripe';
98
import './polyfills/compression';
109
// import { checkBotId } from "botid/server";
@@ -37,7 +36,6 @@ const app = new Elysia()
3736
.use(basketRouter)
3837
.use(stripeRouter)
3938
.use(emailRouter)
40-
.use(observabilityRouter)
4139
.get('/health', () => ({ status: 'ok', version: '1.0.0' }));
4240

4341
export default {

apps/basket/src/routes/observability.ts

Lines changed: 0 additions & 172 deletions
This file was deleted.

0 commit comments

Comments
 (0)