rename communityEcology → board across backend
Model, schemas, API routes, activity log, and all server handlers updated. Old ecology/ and community-ecology routes removed, new board/ routes added. Tests updated and new board-suggestions tests written (10 cases).
This commit is contained in:
parent
59d6e97787
commit
091ec58073
20 changed files with 405 additions and 80 deletions
|
|
@ -76,8 +76,8 @@ const formatters = {
|
||||||
text: 'Updated community connections',
|
text: 'Updated community connections',
|
||||||
icon: 'i-lucide-users'
|
icon: 'i-lucide-users'
|
||||||
}),
|
}),
|
||||||
community_ecology_updated: () => ({
|
board_updated: () => ({
|
||||||
text: 'Updated community ecology',
|
text: 'Updated board',
|
||||||
icon: 'i-lucide-users'
|
icon: 'i-lucide-users'
|
||||||
}),
|
}),
|
||||||
connection_requested: (m) => ({
|
connection_requested: (m) => ({
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ export default defineEventHandler(async (event) => {
|
||||||
location: member.location,
|
location: member.location,
|
||||||
socialLinks: member.socialLinks,
|
socialLinks: member.socialLinks,
|
||||||
craftTags: member.craftTags,
|
craftTags: member.craftTags,
|
||||||
communityEcology: member.communityEcology,
|
board: member.board,
|
||||||
showInDirectory: member.showInDirectory,
|
showInDirectory: member.showInDirectory,
|
||||||
notifications: member.notifications,
|
notifications: member.notifications,
|
||||||
privacy: member.privacy,
|
privacy: member.privacy,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ export default defineEventHandler(async (event) => {
|
||||||
const member = await requireAuth(event)
|
const member = await requireAuth(event)
|
||||||
const memberId = member._id
|
const memberId = member._id
|
||||||
|
|
||||||
const topics = member.communityEcology?.topics || []
|
const topics = member.board?.topics || []
|
||||||
if (!topics.length) {
|
if (!topics.length) {
|
||||||
return { suggestions: [] }
|
return { suggestions: [] }
|
||||||
}
|
}
|
||||||
|
|
@ -26,9 +26,9 @@ export default defineEventHandler(async (event) => {
|
||||||
const candidates = await Member.find({
|
const candidates = await Member.find({
|
||||||
_id: { $ne: memberId },
|
_id: { $ne: memberId },
|
||||||
status: 'active',
|
status: 'active',
|
||||||
'communityEcology.topics.tagSlug': { $in: mySlugs },
|
'board.topics.tagSlug': { $in: mySlugs },
|
||||||
})
|
})
|
||||||
.select('name avatar craftTags circle communityEcology privacy')
|
.select('name avatar craftTags circle board privacy')
|
||||||
.lean()
|
.lean()
|
||||||
|
|
||||||
if (!candidates.length) {
|
if (!candidates.length) {
|
||||||
|
|
@ -42,7 +42,7 @@ export default defineEventHandler(async (event) => {
|
||||||
|
|
||||||
const suggestions = []
|
const suggestions = []
|
||||||
for (const candidate of candidates) {
|
for (const candidate of candidates) {
|
||||||
const theirTopics = candidate.communityEcology?.topics || []
|
const theirTopics = candidate.board?.topics || []
|
||||||
const matchingTags = []
|
const matchingTags = []
|
||||||
|
|
||||||
for (const theirTopic of theirTopics) {
|
for (const theirTopic of theirTopics) {
|
||||||
|
|
@ -79,8 +79,8 @@ export default defineEventHandler(async (event) => {
|
||||||
// Expose slackHandle only when the candidate has opted into peer support.
|
// Expose slackHandle only when the candidate has opted into peer support.
|
||||||
// Slack handle is the contact-in-place path — without it, there is no way
|
// Slack handle is the contact-in-place path — without it, there is no way
|
||||||
// for the current member to reach out.
|
// for the current member to reach out.
|
||||||
if (candidate.communityEcology?.offerPeerSupport && candidate.communityEcology?.slackHandle) {
|
if (candidate.board?.offerPeerSupport && candidate.board?.slackHandle) {
|
||||||
filtered.slackHandle = candidate.communityEcology.slackHandle
|
filtered.slackHandle = candidate.board.slackHandle
|
||||||
}
|
}
|
||||||
|
|
||||||
suggestions.push({
|
suggestions.push({
|
||||||
|
|
@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
|
||||||
|
|
||||||
// Combine craft tags and cooperative ecology tags
|
// Combine craft tags and cooperative ecology tags
|
||||||
const craftTags = member.craftTags || []
|
const craftTags = member.craftTags || []
|
||||||
const ecologyTags = (member.communityEcology?.topics || []).map(t => t.tagSlug)
|
const ecologyTags = (member.board?.topics || []).map(t => t.tagSlug)
|
||||||
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
||||||
|
|
||||||
if (!memberTags.length) {
|
if (!memberTags.length) {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ export default defineEventHandler(async (event) => {
|
||||||
status: "active",
|
status: "active",
|
||||||
})
|
})
|
||||||
.select(
|
.select(
|
||||||
"name pronouns timeZone avatar studio bio location socialLinks privacy circle craftTags communityEcology createdAt memberNumber",
|
"name pronouns timeZone avatar studio bio location socialLinks privacy circle craftTags board createdAt memberNumber",
|
||||||
)
|
)
|
||||||
.lean();
|
.lean();
|
||||||
|
|
||||||
|
|
@ -70,18 +70,18 @@ export default defineEventHandler(async (event) => {
|
||||||
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
||||||
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
||||||
|
|
||||||
if (isVisible("communityEcology")) {
|
if (isVisible("board")) {
|
||||||
const ecology = member.communityEcology || {};
|
const board = member.board || {};
|
||||||
filtered.communityEcology = {
|
filtered.board = {
|
||||||
topics: ecology.topics,
|
topics: board.topics,
|
||||||
offerPeerSupport: ecology.offerPeerSupport,
|
offerPeerSupport: board.offerPeerSupport,
|
||||||
availability: ecology.availability,
|
availability: board.availability,
|
||||||
details: ecology.details,
|
details: board.details,
|
||||||
// Contact-in-place: surface the handle + personal message only when
|
// Contact-in-place: surface the handle + personal message only when
|
||||||
// the member has explicitly opted into peer support.
|
// the member has explicitly opted into peer support.
|
||||||
...(ecology.offerPeerSupport && {
|
...(board.offerPeerSupport && {
|
||||||
slackHandle: ecology.slackHandle,
|
slackHandle: board.slackHandle,
|
||||||
personalMessage: ecology.personalMessage,
|
personalMessage: board.personalMessage,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ export default defineEventHandler(async (event) => {
|
||||||
const andConditions = [];
|
const andConditions = [];
|
||||||
|
|
||||||
if (peerSupport === "true") {
|
if (peerSupport === "true") {
|
||||||
dbQuery["communityEcology.offerPeerSupport"] = true;
|
dbQuery["board.offerPeerSupport"] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (search) {
|
if (search) {
|
||||||
|
|
@ -56,7 +56,7 @@ export default defineEventHandler(async (event) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connectionTag) {
|
if (connectionTag) {
|
||||||
dbQuery["communityEcology.topics.tagSlug"] = connectionTag;
|
dbQuery["board.topics.tagSlug"] = connectionTag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (andConditions.length > 0) {
|
if (andConditions.length > 0) {
|
||||||
|
|
@ -66,7 +66,7 @@ export default defineEventHandler(async (event) => {
|
||||||
try {
|
try {
|
||||||
const members = await Member.find(dbQuery)
|
const members = await Member.find(dbQuery)
|
||||||
.select(
|
.select(
|
||||||
"name pronouns timeZone avatar studio bio location socialLinks privacy circle craftTags communityEcology createdAt",
|
"name pronouns timeZone avatar studio bio location socialLinks privacy circle craftTags board createdAt",
|
||||||
)
|
)
|
||||||
.sort({ createdAt: -1 })
|
.sort({ createdAt: -1 })
|
||||||
.lean();
|
.lean();
|
||||||
|
|
@ -96,14 +96,14 @@ export default defineEventHandler(async (event) => {
|
||||||
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
if (isVisible("socialLinks")) filtered.socialLinks = member.socialLinks;
|
||||||
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
if (isVisible("craftTags")) filtered.craftTags = member.craftTags;
|
||||||
|
|
||||||
if (isVisible("communityEcology")) {
|
if (isVisible("board")) {
|
||||||
const ecology = member.communityEcology || {};
|
const board = member.board || {};
|
||||||
filtered.communityEcology = {
|
filtered.board = {
|
||||||
topics: ecology.topics,
|
topics: board.topics,
|
||||||
offerPeerSupport: ecology.offerPeerSupport,
|
offerPeerSupport: board.offerPeerSupport,
|
||||||
availability: ecology.availability,
|
availability: board.availability,
|
||||||
...(ecology.offerPeerSupport && {
|
...(board.offerPeerSupport && {
|
||||||
slackHandle: ecology.slackHandle,
|
slackHandle: board.slackHandle,
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,15 @@ export default defineEventHandler(async (event) => {
|
||||||
await connectDB()
|
await connectDB()
|
||||||
const member = await requireAuth(event)
|
const member = await requireAuth(event)
|
||||||
|
|
||||||
const body = await validateBody(event, communityEcologyUpdateSchema)
|
const body = await validateBody(event, boardUpdateSchema)
|
||||||
|
|
||||||
const updateData = {
|
const updateData = {
|
||||||
'communityEcology.topics': body.topics || [],
|
'board.topics': body.topics || [],
|
||||||
'communityEcology.offerPeerSupport': body.offerPeerSupport || false,
|
'board.offerPeerSupport': body.offerPeerSupport || false,
|
||||||
'communityEcology.availability': body.availability || '',
|
'board.availability': body.availability || '',
|
||||||
'communityEcology.slackHandle': body.slackHandle || '',
|
'board.slackHandle': body.slackHandle || '',
|
||||||
'communityEcology.personalMessage': body.personalMessage || '',
|
'board.personalMessage': body.personalMessage || '',
|
||||||
'communityEcology.details': body.details || '',
|
'board.details': body.details || '',
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body.offerPeerSupport && body.slackHandle) {
|
if (body.offerPeerSupport && body.slackHandle) {
|
||||||
|
|
@ -27,12 +27,12 @@ export default defineEventHandler(async (event) => {
|
||||||
updateData.slackUserId = slackUserId
|
updateData.slackUserId = slackUserId
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
console.warn(
|
||||||
`[Community Ecology] Could not find Slack user ID for handle: ${body.slackHandle}`,
|
`[Board] Could not find Slack user ID for handle: ${body.slackHandle}`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('[Community Ecology] Error fetching Slack user ID:', error.message)
|
console.error('[Board] Error fetching Slack user ID:', error.message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,21 +50,21 @@ export default defineEventHandler(async (event) => {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
logActivity(member._id, 'community_ecology_updated', {
|
logActivity(member._id, 'board_updated', {
|
||||||
topicCount: (body.topics || []).length,
|
topicCount: (body.topics || []).length,
|
||||||
offerPeerSupport: body.offerPeerSupport || false,
|
offerPeerSupport: body.offerPeerSupport || false,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
communityEcology: updated.communityEcology,
|
board: updated.board,
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.statusCode) throw error
|
if (error.statusCode) throw error
|
||||||
console.error('Community ecology update error:', error)
|
console.error('Board update error:', error)
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: 500,
|
statusCode: 500,
|
||||||
statusMessage: 'Failed to update community ecology settings',
|
statusMessage: 'Failed to update board settings',
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -32,7 +32,7 @@ export default defineEventHandler(async (event) => {
|
||||||
"locationPrivacy",
|
"locationPrivacy",
|
||||||
"socialLinksPrivacy",
|
"socialLinksPrivacy",
|
||||||
"craftTagsPrivacy",
|
"craftTagsPrivacy",
|
||||||
"communityEcologyPrivacy",
|
"boardPrivacy",
|
||||||
];
|
];
|
||||||
|
|
||||||
// Build update object from validated data
|
// Build update object from validated data
|
||||||
|
|
|
||||||
|
|
@ -5,13 +5,13 @@ export default defineEventHandler(async (event) => {
|
||||||
|
|
||||||
const hasProfileTags =
|
const hasProfileTags =
|
||||||
member.craftTags.length > 0 &&
|
member.craftTags.length > 0 &&
|
||||||
(member.communityEcology?.topics || []).length > 0
|
(member.board?.topics || []).length > 0
|
||||||
|
|
||||||
const hasVisitedEvent = !!member.onboarding?.eventPageVisited
|
const hasVisitedEvent = !!member.onboarding?.eventPageVisited
|
||||||
|
|
||||||
const topics = member.communityEcology?.topics || []
|
const topics = member.board?.topics || []
|
||||||
const hasEngagedEcology =
|
const hasEngagedEcology =
|
||||||
!!member.onboarding?.ecologyPageVisited &&
|
!!member.onboarding?.boardPageVisited &&
|
||||||
topics.some((t) => ['help', 'interested', 'seeking'].includes(t.state))
|
topics.some((t) => ['help', 'interested', 'seeking'].includes(t.state))
|
||||||
|
|
||||||
const hasClickedWiki = !!member.onboarding?.wikiClicked
|
const hasClickedWiki = !!member.onboarding?.wikiClicked
|
||||||
|
|
|
||||||
|
|
@ -32,10 +32,10 @@ export default defineEventHandler(async (event) => {
|
||||||
_id: member._id,
|
_id: member._id,
|
||||||
'onboarding.completedAt': null,
|
'onboarding.completedAt': null,
|
||||||
'onboarding.eventPageVisited': true,
|
'onboarding.eventPageVisited': true,
|
||||||
'onboarding.ecologyPageVisited': true,
|
'onboarding.boardPageVisited': true,
|
||||||
'onboarding.wikiClicked': true,
|
'onboarding.wikiClicked': true,
|
||||||
'craftTags.0': { $exists: true },
|
'craftTags.0': { $exists: true },
|
||||||
'communityEcology.topics': {
|
'board.topics': {
|
||||||
$elemMatch: { state: { $in: ['help', 'interested', 'seeking'] } },
|
$elemMatch: { state: { $in: ['help', 'interested', 'seeking'] } },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ export default defineEventHandler(async (event) => {
|
||||||
|
|
||||||
// Combine craft tags and cooperative ecology tags
|
// Combine craft tags and cooperative ecology tags
|
||||||
const craftTags = member.craftTags || []
|
const craftTags = member.craftTags || []
|
||||||
const ecologyTags = (member.communityEcology?.topics || []).map(t => t.tagSlug)
|
const ecologyTags = (member.board?.topics || []).map(t => t.tagSlug)
|
||||||
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
const memberTags = [...new Set([...craftTags, ...ecologyTags].filter(Boolean))]
|
||||||
|
|
||||||
if (!memberTags.length) {
|
if (!memberTags.length) {
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ const ACTIVITY_TYPES = [
|
||||||
'slack_invited',
|
'slack_invited',
|
||||||
'email_sent',
|
'email_sent',
|
||||||
'community_connections_updated',
|
'community_connections_updated',
|
||||||
'community_ecology_updated',
|
'board_updated',
|
||||||
'connection_requested',
|
'connection_requested',
|
||||||
'connection_confirmed',
|
'connection_confirmed',
|
||||||
'tag_suggested'
|
'tag_suggested'
|
||||||
|
|
|
||||||
|
|
@ -72,7 +72,7 @@ const memberSchema = new mongoose.Schema({
|
||||||
showInDirectory: { type: Boolean, default: true },
|
showInDirectory: { type: Boolean, default: true },
|
||||||
|
|
||||||
craftTags: [String],
|
craftTags: [String],
|
||||||
communityEcology: {
|
board: {
|
||||||
topics: [
|
topics: [
|
||||||
{
|
{
|
||||||
tagSlug: String,
|
tagSlug: String,
|
||||||
|
|
@ -128,7 +128,7 @@ const memberSchema = new mongoose.Schema({
|
||||||
enum: ["public", "members", "private"],
|
enum: ["public", "members", "private"],
|
||||||
default: "members",
|
default: "members",
|
||||||
},
|
},
|
||||||
communityEcology: {
|
board: {
|
||||||
type: String,
|
type: String,
|
||||||
enum: ["public", "members", "private"],
|
enum: ["public", "members", "private"],
|
||||||
default: "members",
|
default: "members",
|
||||||
|
|
@ -155,7 +155,7 @@ const memberSchema = new mongoose.Schema({
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: { type: Date, default: null },
|
completedAt: { type: Date, default: null },
|
||||||
eventPageVisited: { type: Boolean, default: false },
|
eventPageVisited: { type: Boolean, default: false },
|
||||||
ecologyPageVisited: { type: Boolean, default: false },
|
boardPageVisited: { type: Boolean, default: false },
|
||||||
wikiClicked: { type: Boolean, default: false },
|
wikiClicked: { type: Boolean, default: false },
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ export const ACTIVITY_TYPES = {
|
||||||
SLACK_INVITED: 'slack_invited',
|
SLACK_INVITED: 'slack_invited',
|
||||||
EMAIL_SENT: 'email_sent',
|
EMAIL_SENT: 'email_sent',
|
||||||
COMMUNITY_CONNECTIONS_UPDATED: 'community_connections_updated',
|
COMMUNITY_CONNECTIONS_UPDATED: 'community_connections_updated',
|
||||||
COMMUNITY_ECOLOGY_UPDATED: 'community_ecology_updated',
|
BOARD_UPDATED: 'board_updated',
|
||||||
CONNECTION_REQUESTED: 'connection_requested',
|
CONNECTION_REQUESTED: 'connection_requested',
|
||||||
CONNECTION_CONFIRMED: 'connection_confirmed',
|
CONNECTION_CONFIRMED: 'connection_confirmed',
|
||||||
TAG_SUGGESTED: 'tag_suggested'
|
TAG_SUGGESTED: 'tag_suggested'
|
||||||
|
|
@ -40,7 +40,7 @@ export const ACTIVITY_TYPE_DEFAULTS = {
|
||||||
slack_invited: 'admin',
|
slack_invited: 'admin',
|
||||||
email_sent: 'member',
|
email_sent: 'member',
|
||||||
community_connections_updated: 'member',
|
community_connections_updated: 'member',
|
||||||
community_ecology_updated: 'member',
|
board_updated: 'member',
|
||||||
connection_requested: 'member',
|
connection_requested: 'member',
|
||||||
connection_confirmed: 'member',
|
connection_confirmed: 'member',
|
||||||
tag_suggested: 'member'
|
tag_suggested: 'member'
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export const memberProfileUpdateSchema = z.object({
|
||||||
socialLinksPrivacy: privacyEnum.optional(),
|
socialLinksPrivacy: privacyEnum.optional(),
|
||||||
craftTags: z.array(z.string().max(100)).max(16).optional(),
|
craftTags: z.array(z.string().max(100)).max(16).optional(),
|
||||||
craftTagsPrivacy: privacyEnum.optional(),
|
craftTagsPrivacy: privacyEnum.optional(),
|
||||||
communityEcologyPrivacy: privacyEnum.optional()
|
boardPrivacy: privacyEnum.optional()
|
||||||
})
|
})
|
||||||
|
|
||||||
export const eventRegistrationSchema = z.object({
|
export const eventRegistrationSchema = z.object({
|
||||||
|
|
@ -367,7 +367,7 @@ export const inviteAcceptSchema = z.object({
|
||||||
// --- Onboarding schemas ---
|
// --- Onboarding schemas ---
|
||||||
|
|
||||||
export const onboardingTrackSchema = z.object({
|
export const onboardingTrackSchema = z.object({
|
||||||
goal: z.enum(['eventPageVisited', 'ecologyPageVisited', 'wikiClicked'])
|
goal: z.enum(['eventPageVisited', 'boardPageVisited', 'wikiClicked'])
|
||||||
})
|
})
|
||||||
|
|
||||||
// --- Tag schemas ---
|
// --- Tag schemas ---
|
||||||
|
|
@ -377,7 +377,7 @@ export const tagSuggestionSchema = z.object({
|
||||||
pool: z.enum(['craft', 'cooperative'])
|
pool: z.enum(['craft', 'cooperative'])
|
||||||
})
|
})
|
||||||
|
|
||||||
export const communityEcologyUpdateSchema = z.object({
|
export const boardUpdateSchema = z.object({
|
||||||
topics: z.array(z.object({
|
topics: z.array(z.object({
|
||||||
tagSlug: z.string().min(1).max(100),
|
tagSlug: z.string().min(1).max(100),
|
||||||
state: z.enum(['help', 'interested', 'seeking'])
|
state: z.enum(['help', 'interested', 'seeking'])
|
||||||
|
|
|
||||||
325
tests/server/api/board-suggestions.test.js
Normal file
325
tests/server/api/board-suggestions.test.js
Normal file
|
|
@ -0,0 +1,325 @@
|
||||||
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
|
|
||||||
|
const { mockFind, mockSelect, mockLean } = vi.hoisted(() => ({
|
||||||
|
mockFind: vi.fn(),
|
||||||
|
mockSelect: vi.fn(),
|
||||||
|
mockLean: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('../../../server/models/member.js', () => ({
|
||||||
|
default: { find: mockFind }
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('../../../server/utils/mongoose.js', () => ({
|
||||||
|
connectDB: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
|
vi.mock('../../../server/utils/auth.js', () => ({
|
||||||
|
requireAuth: vi.fn()
|
||||||
|
}))
|
||||||
|
|
||||||
|
import { requireAuth } from '../../../server/utils/auth.js'
|
||||||
|
import handler from '../../../server/api/board/suggestions.get.js'
|
||||||
|
import { createMockEvent } from '../helpers/createMockEvent.js'
|
||||||
|
|
||||||
|
function setupChain(result = []) {
|
||||||
|
mockLean.mockResolvedValue(result)
|
||||||
|
mockSelect.mockReturnValue({ lean: mockLean })
|
||||||
|
mockFind.mockReturnValue({ select: mockSelect })
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeMember(overrides = {}) {
|
||||||
|
return {
|
||||||
|
_id: 'member-1',
|
||||||
|
board: { topics: [] },
|
||||||
|
...overrides
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeCandidate(overrides = {}) {
|
||||||
|
return {
|
||||||
|
_id: 'candidate-1',
|
||||||
|
name: 'Test Candidate',
|
||||||
|
circle: 'community',
|
||||||
|
avatar: '/avatar.jpg',
|
||||||
|
craftTags: ['game-design'],
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'interested' }
|
||||||
|
],
|
||||||
|
offerPeerSupport: false,
|
||||||
|
slackHandle: ''
|
||||||
|
},
|
||||||
|
privacy: {},
|
||||||
|
...overrides
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('GET /api/board/suggestions', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns empty suggestions when member has no topics', async () => {
|
||||||
|
const member = makeMember({ board: { topics: [] } })
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result).toEqual({ suggestions: [] })
|
||||||
|
expect(mockFind).not.toHaveBeenCalled()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('returns matching members with shared topics and correct state comparison', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'help' },
|
||||||
|
{ tagSlug: 'co-op-governance', state: 'seeking' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const candidate = makeCandidate({
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'interested' }
|
||||||
|
],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setupChain([candidate])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions).toHaveLength(1)
|
||||||
|
expect(result.suggestions[0].matchingTags).toEqual([
|
||||||
|
{ tagSlug: 'revenue-sharing', yourState: 'help', theirState: 'interested' }
|
||||||
|
])
|
||||||
|
expect(result.suggestions[0].matchCount).toBe(1)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('excludes the requesting member from results', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
_id: 'member-1',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'help' }]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
setupChain([])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
await handler(event)
|
||||||
|
|
||||||
|
expect(mockFind).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
_id: { $ne: 'member-1' }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('respects avatar privacy settings', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'help' }]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const candidate = makeCandidate({
|
||||||
|
privacy: { avatar: 'private' },
|
||||||
|
avatar: '/secret-avatar.jpg',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setupChain([candidate])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions[0].member.avatar).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('respects craftTags privacy settings', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'help' }]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const candidate = makeCandidate({
|
||||||
|
privacy: { craftTags: 'private' },
|
||||||
|
craftTags: ['game-design'],
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setupChain([candidate])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions[0].member.craftTags).toBeUndefined()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('exposes avatar when privacy is public', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'help' }]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const candidate = makeCandidate({
|
||||||
|
privacy: { avatar: 'public' },
|
||||||
|
avatar: '/public-avatar.jpg',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
setupChain([candidate])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions[0].member.avatar).toBe('/public-avatar.jpg')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('only exposes slackHandle when offerPeerSupport is true AND slackHandle is set', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'help' }]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
// Case 1: offerPeerSupport false — no slackHandle
|
||||||
|
const noSupport = makeCandidate({
|
||||||
|
_id: 'c1',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: false,
|
||||||
|
slackHandle: 'someone'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Case 2: offerPeerSupport true but no slackHandle
|
||||||
|
const supportNoHandle = makeCandidate({
|
||||||
|
_id: 'c2',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: true,
|
||||||
|
slackHandle: ''
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Case 3: offerPeerSupport true AND slackHandle set
|
||||||
|
const supportWithHandle = makeCandidate({
|
||||||
|
_id: 'c3',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: true,
|
||||||
|
slackHandle: 'helpfulperson'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
setupChain([noSupport, supportNoHandle, supportWithHandle])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions[0].member.slackHandle).toBeUndefined()
|
||||||
|
expect(result.suggestions[1].member.slackHandle).toBeUndefined()
|
||||||
|
expect(result.suggestions[2].member.slackHandle).toBe('helpfulperson')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('filters by tag query param', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'help' },
|
||||||
|
{ tagSlug: 'co-op-governance', state: 'seeking' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
setupChain([])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions?tag=revenue-sharing' })
|
||||||
|
await handler(event)
|
||||||
|
|
||||||
|
// Should only query for the filtered tag
|
||||||
|
expect(mockFind).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
'board.topics.tagSlug': { $in: ['revenue-sharing'] }
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('sorts by matchCount descending', async () => {
|
||||||
|
const member = makeMember({
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'help' },
|
||||||
|
{ tagSlug: 'co-op-governance', state: 'seeking' },
|
||||||
|
{ tagSlug: 'profit-sharing', state: 'interested' }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
})
|
||||||
|
requireAuth.mockResolvedValue(member)
|
||||||
|
|
||||||
|
const oneMatch = makeCandidate({
|
||||||
|
_id: 'c1',
|
||||||
|
name: 'One Match',
|
||||||
|
board: {
|
||||||
|
topics: [{ tagSlug: 'revenue-sharing', state: 'interested' }],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
const twoMatches = makeCandidate({
|
||||||
|
_id: 'c2',
|
||||||
|
name: 'Two Matches',
|
||||||
|
board: {
|
||||||
|
topics: [
|
||||||
|
{ tagSlug: 'revenue-sharing', state: 'help' },
|
||||||
|
{ tagSlug: 'co-op-governance', state: 'interested' }
|
||||||
|
],
|
||||||
|
offerPeerSupport: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
setupChain([oneMatch, twoMatches])
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
const result = await handler(event)
|
||||||
|
|
||||||
|
expect(result.suggestions[0].matchCount).toBe(2)
|
||||||
|
expect(result.suggestions[0].member.name).toBe('Two Matches')
|
||||||
|
expect(result.suggestions[1].matchCount).toBe(1)
|
||||||
|
expect(result.suggestions[1].member.name).toBe('One Match')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('requires auth (401)', async () => {
|
||||||
|
requireAuth.mockRejectedValue(
|
||||||
|
createError({ statusCode: 401, statusMessage: 'Unauthorized' })
|
||||||
|
)
|
||||||
|
|
||||||
|
const event = createMockEvent({ method: 'GET', path: '/api/board/suggestions' })
|
||||||
|
|
||||||
|
await expect(handler(event)).rejects.toMatchObject({
|
||||||
|
statusCode: 401
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
@ -39,7 +39,7 @@ function makeMember(overrides = {}) {
|
||||||
return {
|
return {
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
...overrides
|
...overrides
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -82,9 +82,9 @@ describe('GET /api/events/recommended', () => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns events matching cooperative tags from communityEcology.topics', async () => {
|
it('returns events matching cooperative tags from board.topics', async () => {
|
||||||
const member = makeMember({
|
const member = makeMember({
|
||||||
communityEcology: {
|
board: {
|
||||||
topics: [
|
topics: [
|
||||||
{ tagSlug: 'revenue-sharing', state: 'interested' },
|
{ tagSlug: 'revenue-sharing', state: 'interested' },
|
||||||
{ tagSlug: 'co-op-governance', state: 'help' }
|
{ tagSlug: 'co-op-governance', state: 'help' }
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -50,13 +50,13 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: ['game-design'],
|
craftTags: ['game-design'],
|
||||||
communityEcology: {
|
board: {
|
||||||
topics: [{ tagSlug: 'governance', state: 'interested' }],
|
topics: [{ tagSlug: 'governance', state: 'interested' }],
|
||||||
},
|
},
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -72,11 +72,11 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: ['game-design'],
|
craftTags: ['game-design'],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -92,13 +92,13 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: {
|
board: {
|
||||||
topics: [{ tagSlug: 'governance', state: 'help' }],
|
topics: [{ tagSlug: 'governance', state: 'help' }],
|
||||||
},
|
},
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: true,
|
boardPageVisited: true,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -114,11 +114,11 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: true,
|
boardPageVisited: true,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -134,11 +134,11 @@ describe('GET /api/onboarding/status', () => {
|
||||||
requireAuth.mockResolvedValue({
|
requireAuth.mockResolvedValue({
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: true,
|
eventPageVisited: true,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: true,
|
wikiClicked: true,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ describe('POST /api/onboarding/track', () => {
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: false,
|
eventPageVisited: false,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -108,7 +108,7 @@ describe('POST /api/onboarding/track', () => {
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: null,
|
completedAt: null,
|
||||||
eventPageVisited: true,
|
eventPageVisited: true,
|
||||||
ecologyPageVisited: false,
|
boardPageVisited: false,
|
||||||
wikiClicked: false,
|
wikiClicked: false,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
@ -138,7 +138,7 @@ describe('POST /api/onboarding/track', () => {
|
||||||
onboarding: {
|
onboarding: {
|
||||||
completedAt: new Date(),
|
completedAt: new Date(),
|
||||||
eventPageVisited: true,
|
eventPageVisited: true,
|
||||||
ecologyPageVisited: true,
|
boardPageVisited: true,
|
||||||
wikiClicked: true,
|
wikiClicked: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ function makeMember(overrides = {}) {
|
||||||
return {
|
return {
|
||||||
_id: 'member-1',
|
_id: 'member-1',
|
||||||
craftTags: [],
|
craftTags: [],
|
||||||
communityEcology: { topics: [] },
|
board: { topics: [] },
|
||||||
...overrides
|
...overrides
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue