Skip to content

Commit

Permalink
Correctly update feedback count on my teaching page
Browse files Browse the repository at this point in the history
  • Loading branch information
Veikkosuhonen committed Jan 8, 2025
1 parent f01ad0f commit f33044f
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 16 deletions.
40 changes: 31 additions & 9 deletions cypress/integration/feedbackCount.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,24 @@ describe('Feedback count', () => {
cy.getTestFbtId().as('fbtId')
})

it('Feedback count increases on feedback page when a student gives feedback', () => {
// Initial feedback count
it('Feedback count increases everywhere when a student gives feedback', () => {
cy.loginAs(teacher)
// Initial feedback count on my teaching page
cy.visit('/courses')
cy.get('@fbtId')
.then(id => cy.get(`[data-cy="my-teaching-feedback-target-secondary-text-${id}"]`))
.invoke('text')
.then(text => {
cy.wrap(text).as('myTeachingInitialCount')
})

// Initial feedback count on feedback page
cy.get('@fbtId').then(id => cy.visit(`/targets/${id}`))
cy.get('[data-cy=feedback-target-feedback-count-percentage]').invoke('text').then(text => {
cy.wrap(text).as('initialCount')
})
cy.get('[data-cy=feedback-target-feedback-count-percentage]')
.invoke('text')
.then(text => {
cy.wrap(text).as('fbtPageInitialCount')
})

// Student gives feedback
cy.loginAs(student)
Expand All @@ -33,17 +44,28 @@ describe('Feedback count', () => {
cy.get('[data-cy=feedback-view-give-feedback]').click()
cy.contains('Feedback has been given. Thank you for your feedback!')

// Verify feedback count increased
// Verify feedback count increased on feedback page
cy.loginAs(teacher)
cy.get('@fbtId').then(id => cy.visit(`/targets/${id}`))
cy.get('[data-cy=feedback-target-feedback-count-percentage]').invoke('text').then(newCount => {
cy.get('@initialCount').then(initialCount => {
cy.get('@fbtPageInitialCount').then(initialCount => {
const newCountInt = parseInt(newCount.split("/")[0], 10)
console.log(newCountInt)
const initialCountInt = parseInt(initialCount.split("/")[0], 10)
console.log(initialCountInt)
expect(newCountInt).to.eq(initialCountInt + 1)
})
})

// Verify feedback count increased on my teaching page
cy.visit('/courses')
cy.get('@fbtId')
.then(id => cy.get(`[data-cy="my-teaching-feedback-target-secondary-text-${id}"]`))
.invoke('text')
.then(newCount => {
cy.get('@myTeachingInitialCount').then(initialCount => {
const newCountInt = parseInt(newCount.split("/")[0], 10)
const initialCountInt = parseInt(initialCount.split("/")[0], 10)
expect(newCountInt).to.eq(initialCountInt + 1)
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@ const FeedbackTargetSecondaryText = ({ feedbackTarget }) => {
const feedbackPercentage = getFeedbackPercentageString(feedbackTarget)

return (
<Typography variant="body2" color="textSecondary" component="span">
<Typography
variant="body2"
color="textSecondary"
component="span"
data-cy={`my-teaching-feedback-target-secondary-text-${feedbackTarget.id}`}
>
{parseISO(feedbackTarget.opensAt) < new Date() ? (
<>
{t('teacherView:feedbackCount', {
Expand Down
1 change: 1 addition & 0 deletions src/server/db/dbConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const connectToDatabase = async (attempt = 0) => {
return process.exit(1)
}
logger.info(`Connection to database failed! Attempt ${attempt} of ${DB_CONNECTION_RETRY_LIMIT}`)
// eslint-disable-next-line no-console
console.log(err)
await sleep(5000)
return connectToDatabase(attempt + 1)
Expand Down
3 changes: 3 additions & 0 deletions src/server/models/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ Feedback.afterCreate(async feedback => {
//@ts-expect-error fbt is not yet typescripted
await feedbackTargetCache.set(fbt.id, cachedFbt)

// Because sequelize is soo "optimized", we need to manually mark the field as changed
summary.changed('data', true)
await summary.save()
})

Expand Down Expand Up @@ -85,6 +87,7 @@ Feedback.afterDestroy(async feedback => {
//@ts-expect-error fbt is not yet typescripted
await feedbackTargetCache.set(fbt.id, cachedFbt)

summary.changed('data', true)
await summary.save()
})

Expand Down
13 changes: 7 additions & 6 deletions src/server/routes/courseUnits/courseUnitController.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ const getCourseUnitsForTeacher = async (req, res) => {
},
],
},
include: {
model: Summary,
required: false,
as: 'summary',
},
},
{
model: Summary,
required: false,
as: 'summary',
},
{
model: CourseUnit,
Expand Down Expand Up @@ -181,7 +181,8 @@ const getCourseUnitsForTeacher = async (req, res) => {
...feedbackTarget.courseRealisation.toJSON(),
feedbackResponseGiven: feedbackTarget.dataValues.feedbackResponseGiven,
feedbackResponseSent: feedbackTarget.dataValues.feedbackResponseSent,
feedbackCount: Number(feedbackTarget.courseRealisation.summary?.feedbackCount ?? 0),
feedbackCount: feedbackTarget.summary?.feedbackCount ?? 0,
studentCount: feedbackTarget.summary?.studentCount ?? 0,
feedbackTarget: _.pick(feedbackTarget, targetFields),
}
: null
Expand Down

0 comments on commit f33044f

Please sign in to comment.