feat: update tests + seed script, add ecology→board migration

- useOnboarding.test.js: hasEngagedEcology→hasEngagedBoard, /api/ecology/suggestions→/api/board/suggestions, ecology key/route→board in test assertions
- onboarding-status.test.js: stale description strings updated
- seed-welcome-tester.cjs: communityEcology→board, ecologyPageVisited→boardPageVisited
- migrate-ecology-to-board.cjs: one-time migration renames three member fields and activity log action values
This commit is contained in:
Jennie Robinson Faber 2026-04-14 12:20:46 +01:00
parent 49c54764c6
commit 74b2287d48
4 changed files with 95 additions and 26 deletions

View file

@ -0,0 +1,69 @@
/**
* One-time migration: rename ecology fields to board across members and activity logs.
*
* Renames on Member documents:
* communityEcology board
* privacy.communityEcology privacy.board
* onboarding.ecologyPageVisited onboarding.boardPageVisited
*
* Renames on ActivityLog documents:
* action: 'community_ecology_updated' action: 'board_updated'
*
* Usage: node scripts/migrate-ecology-to-board.cjs
*/
require('dotenv').config()
const mongoose = require('mongoose')
async function main() {
const uri = process.env.MONGODB_URI
if (!uri) {
console.error('MONGODB_URI is not set. Aborting.')
process.exit(1)
}
await mongoose.connect(uri)
console.log('Connected to MongoDB.')
const Member = mongoose.connection.model(
'Member',
new mongoose.Schema({}, { strict: false, collection: 'members' }),
)
const ActivityLog = mongoose.connection.model(
'ActivityLog',
new mongoose.Schema({}, { strict: false, collection: 'activitylogs' }),
)
// --- Rename member fields ---
const memberResult = await Member.updateMany(
{},
{
$rename: {
communityEcology: 'board',
'privacy.communityEcology': 'privacy.board',
'onboarding.ecologyPageVisited': 'onboarding.boardPageVisited',
},
},
{ strict: false },
)
console.log(
`Members updated: ${memberResult.modifiedCount} modified (${memberResult.matchedCount} matched).`,
)
// --- Rename activity log action values ---
const logResult = await ActivityLog.updateMany(
{ action: 'community_ecology_updated' },
{ $set: { action: 'board_updated' } },
)
console.log(
`Activity logs updated: ${logResult.modifiedCount} modified (${logResult.matchedCount} matched).`,
)
await mongoose.disconnect()
console.log('Done. Disconnected from MongoDB.')
}
main().catch((err) => {
console.error(err)
process.exit(1)
})

View file

@ -1,6 +1,6 @@
/**
* Seed a fresh member in the right state to test the Welcome Workflow.
* All onboarding flags default to false/null, no craft tags, no ecology topics.
* All onboarding flags default to false/null, no craft tags, no board topics.
*
* Usage: node scripts/seed-welcome-tester.js
* Then pick "Welcome Tester" from the dev login dropdown.
@ -29,11 +29,11 @@ async function main() {
role: "member",
status: "active",
craftTags: [],
communityEcology: { topics: [], offerPeerSupport: false },
board: { topics: [], offerPeerSupport: false },
onboarding: {
completedAt: null,
eventPageVisited: false,
ecologyPageVisited: false,
boardPageVisited: false,
wikiClicked: false,
},
},