Skip to content

Commit

Permalink
try test-helper in dedicated file again, this time actually with file…
Browse files Browse the repository at this point in the history
… added
  • Loading branch information
PatrickNercessian committed Sep 13, 2024
1 parent 0323ae0 commit 68a7d7b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
18 changes: 0 additions & 18 deletions db/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { migrateWithPgClient as migrateEvaluateDB } from 'spark-evaluate/lib/migrate.js'
import { mapParticipantsToIds } from 'spark-evaluate/lib/platform-stats.js'
import pg from 'pg'
import { dirname, join } from 'node:path'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -110,20 +109,3 @@ export const migrateStatsDB = async (client) => {

console.log('Migrated `spark-stats` DB schema to version', await postgrator.getDatabaseVersion())
}

/**
* @param {import('./typings.js').Queryable} pgPool
* @param {string} day
* @param {string[]} participantAddresses
*/
export const givenDailyParticipants = async (pgPool, day, participantAddresses) => {
const ids = await mapParticipantsToIds(pgPool, new Set(participantAddresses))
await pgPool.query(`
INSERT INTO daily_participants (day, participant_id)
SELECT $1 as day, UNNEST($2::INT[]) AS participant_id
ON CONFLICT DO NOTHING
`, [
day,
Array.from(ids.values())
])
}
18 changes: 18 additions & 0 deletions db/test-helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { mapParticipantsToIds } from 'spark-evaluate/lib/platform-stats.js'

/**
* @param {import('./typings.js').Queryable} pgPool
* @param {string} day
* @param {string[]} participantAddresses
*/
export const givenDailyParticipants = async (pgPool, day, participantAddresses) => {
const ids = await mapParticipantsToIds(pgPool, new Set(participantAddresses))
await pgPool.query(`
INSERT INTO daily_participants (day, participant_id)
SELECT $1 as day, UNNEST($2::INT[]) AS participant_id
ON CONFLICT DO NOTHING
`, [
day,
Array.from(ids.values())
])
}
3 changes: 2 additions & 1 deletion observer/test/observer.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'node:assert'
import { beforeEach, describe, it } from 'mocha'
import { getPgPools, givenDailyParticipants } from '@filecoin-station/spark-stats-db'
import { getPgPools } from '@filecoin-station/spark-stats-db'
import { givenDailyParticipants } from '@filecoin-station/spark-stats-db/test-helpers.js'

import { observeTransferEvents, observeScheduledRewards } from '../lib/observer.js'

Expand Down
3 changes: 2 additions & 1 deletion stats/test/handler.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import http from 'node:http'
import { once } from 'node:events'
import assert from 'node:assert'
import createDebug from 'debug'
import { getPgPools, givenDailyParticipants } from '@filecoin-station/spark-stats-db'
import { getPgPools } from '@filecoin-station/spark-stats-db'
import { givenDailyParticipants } from '@filecoin-station/spark-stats-db/test-helpers.js'

import { assertResponseStatus, getPort } from './test-helpers.js'
import { createHandler } from '../lib/handler.js'
Expand Down

0 comments on commit 68a7d7b

Please sign in to comment.