Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"watch": "tsx watch src/index.ts",
"build": "npx tsc -p tsconfig.build.json",
"dc": "docker compose -f docker-compose.yml -f docker-compose.dev.yml",
"seed": "DB_HOST=127.0.0.1 tsx tests/seed.ts",
"seed": "DB_HOST=127.0.0.1 CLICKHOUSE_HOST=127.0.0.1 tsx tests/seed.ts",
"test": "./tests/run-tests.sh",
"up": "npm run dc -- up --build -d",
"down": "npm run dc -- down",
Expand Down
40 changes: 35 additions & 5 deletions tests/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import PricingPlanAction, { PricingPlanActionType } from '../src/entities/pricin
import OrganisationPricingPlanFactory from './fixtures/OrganisationPricingPlanFactory'
import PricingPlan from '../src/entities/pricing-plan'
import APIKey, { APIKeyScope } from '../src/entities/api-key'
import GameFeedbackCategoryFactory from './fixtures/GameFeedbackCategoryFactory'
import GameFeedbackFactory from './fixtures/GameFeedbackFactory'
import createClickhouseClient from '../src/lib/clickhouse/createClient'

(async () => {
console.info('Running migrations...')
Expand All @@ -25,7 +28,7 @@ import APIKey, { APIKeyScope } from '../src/entities/api-key'
await orm.em.getConnection().execute('drop table if exists mikro_orm_migrations')
await orm.getMigrator().up()

console.info('Seeding database...')
console.info('Seeding DB...')

const plansMap: Partial<PricingPlan>[] = [
{ stripeId: 'prod_LcO5U04wEGWgMP', default: true },
Expand Down Expand Up @@ -97,8 +100,6 @@ import APIKey, { APIKeyScope } from '../src/entities/api-key'

const players = await new PlayerFactory(games).many(50)

const eventsThisMonth = await new EventFactory(players).thisMonth().many(300)

const leaderboards = await new LeaderboardFactory(games).withEntries().many(6)

const gameSaves = await new GameSaveFactory(players).many(10)
Expand All @@ -114,6 +115,23 @@ import APIKey, { APIKeyScope } from '../src/entities/api-key'
}
}

const feedback = []
for (const game of games) {
const categories = [
await new GameFeedbackCategoryFactory(game).state(() => ({ internalName: 'bugs', name: 'Bugs', anonymised: false })).one(),
await new GameFeedbackCategoryFactory(game).state(() => ({ internalName: 'feedback', name: 'Feedback', anonymised: true })).one()
]

for (const category of categories) {
const items = await new GameFeedbackFactory(game).state(() => ({
category,
playerAlias: casual.random_element(players.filter((player) => player.game === game)).aliases[0],
anonymised: category.anonymised
})).many(5)
feedback.push(...items)
}
}

const em = orm.em.fork()

await em.persistAndFlush([
Expand All @@ -126,14 +144,26 @@ import APIKey, { APIKeyScope } from '../src/entities/api-key'
...games,
...apiKeys,
...players,
...eventsThisMonth,
...leaderboards,
...gameSaves,
...gameStats,
...playerGameStats
...playerGameStats,
...feedback
])

await orm.close(true)

const eventsThisMonth = await new EventFactory(players).thisMonth().many(300)

console.info('Seeding Clickhouse...')

const clickhouse = createClickhouseClient()
await clickhouse.insert({
table: 'events',
values: eventsThisMonth.map((event) => event.getInsertableData()),
format: 'JSONEachRow'
})
clickhouse.close()

console.info('Done!')
})()