Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

finished validation issue number:240 #281

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 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
37 changes: 15 additions & 22 deletions app/dturn/__tests__/rank-statements.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
// https://github.com/EnCiv/civil-pursuit/issues/154
const {
initDiscussion,
insertStatementId,
getStatementIds,
putGroupings,
getUserRecord,
rankMostImportant,
Discussions,
} = require('../dturn')
const { initDiscussion, insertStatementId, getStatementIds, putGroupings, getUserRecord, rankMostImportant, Discussions } = require('../dturn')

const DISCUSSION_ID = 'testRankingDiscussion'
const USER_ID = 'user1'
Expand All @@ -24,37 +16,38 @@ const OPTIONS = {
describe('Test ranking scenarios', () => {
beforeAll(async () => {
await initDiscussion(DISCUSSION_ID, OPTIONS)
const props = []
for (let i = 0; i < 20; i++) {
props.push([DISCUSSION_ID, `user${i}`, `statement${i}`])

const totalStatements = OPTIONS.group_size * 2 - 1
const insertPromises = []
for (let i = 0; i < totalStatements; i++) {
insertPromises.push(insertStatementId(DISCUSSION_ID, `user${i}`, `statement${i}`))
}
for await (const args of props) {
await insertStatementId(...args)
await Promise.all(insertPromises)

console.log(`Checking if ${USER_ID} exists in discussion...`)
if (!Discussions[DISCUSSION_ID].Uitems[USER_ID]) {
console.log(`Inserting statement for ${USER_ID} to ensure it joins the discussion`)
await insertStatementId(DISCUSSION_ID, USER_ID, `statement-${USER_ID}`)
}
})

test('Can rank 2 statements as most important', async () => {
const statements = await getStatementIds(DISCUSSION_ID, 0, USER_ID)

// Ensure statements is defined before proceeding
expect(statements).toBeDefined()
expect(statements.length).toBe(10)

console.log('Retrieved statements:', statements)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay, now that this code is working isn't it time to take the console.log statements out.


const statement1 = statements[0]
const statement2 = statements[1]

// Rank both statements as most important
await rankMostImportant(DISCUSSION_ID, 0, USER_ID, statement1, 1)
await rankMostImportant(DISCUSSION_ID, 0, USER_ID, statement2, 1)

const userRecord = getUserRecord(DISCUSSION_ID, USER_ID)
console.log('User record after ranking:', JSON.stringify(userRecord, null, 2))

// Check that the rankings were applied correctly
expect(userRecord[0].shownStatementIds[statement1].rank).toBe(1)
expect(userRecord[0].shownStatementIds[statement2].rank).toBe(1)
})

afterAll(() => {
delete Discussions[DISCUSSION_ID] // Clean up the discussion
})
})
Loading