Skip to content

Commit

Permalink
Merge pull request #1580 from serlo/fix-order-unrevised
Browse files Browse the repository at this point in the history
fix(unrevised): show new revisions first
  • Loading branch information
hugotiburtino authored Jun 14, 2024
2 parents 8e1ed83 + 2f37e4a commit ea6b2de
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 37 deletions.
117 changes: 80 additions & 37 deletions __tests__/schema/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,96 @@ test('`Subject.id` returns encoded id of subject', async () => {
})
})

const query = new Client()
.prepareQuery({
query: gql`
query ($instance: Instance!) {
subject {
subjects(instance: $instance) {
unrevisedEntities {
nodes {
__typename
id
}
}
}
}
}
`,
})
.withVariables({ instance: 'de' })

const subjects = [
{
unrevisedEntities: {
nodes: [{ __typename: 'Article', id: 34741 }],
},
},
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{
unrevisedEntities: {
nodes: [
{ __typename: 'Article', id: 34907 },
{ __typename: 'Article', id: 35247 },
],
},
},
{
unrevisedEntities: {
nodes: [{ __typename: 'Article', id: 26892 }],
},
},
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
]

test('`Subject.unrevisedEntities` returns list of unrevisedEntities', async () => {
await new Client()
await query.shouldReturnData({
subject: {
subjects,
},
})
})

test('`Subject.unrevisedEntities` shows new revisions first', async () => {
await new Client({ userId: 1 })
.prepareQuery({
query: gql`
query ($instance: Instance!) {
subject {
subjects(instance: $instance) {
unrevisedEntities {
nodes {
__typename
id
}
mutation {
entity {
setAbstractEntity(
input: {
entityType: "Article"
changes: "new revision changes"
entityId: 34907
content: "new content"
subscribeThis: false
subscribeThisByEmail: false
needsReview: true
}
) {
success
}
}
}
`,
})
.withVariables({ instance: 'de' })
.shouldReturnData({
.execute()
const subjectsChangedOrder = [...subjects]
;(subjectsChangedOrder[4] = {
unrevisedEntities: {
nodes: [
{ __typename: 'Article', id: 35247 },
{ __typename: 'Article', id: 34907 },
],
},
}),
await query.shouldReturnData({
subject: {
subjects: [
{
unrevisedEntities: {
nodes: [{ __typename: 'Article', id: 34741 }],
},
},
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{
unrevisedEntities: {
nodes: [
{ __typename: 'Article', id: 34907 },
{ __typename: 'Article', id: 35247 },
],
},
},
{
unrevisedEntities: {
nodes: [{ __typename: 'Article', id: 26892 }],
},
},
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
{ unrevisedEntities: { nodes: [] } },
],
subjects: subjectsChangedOrder,
},
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,7 @@ export async function resolveUnrevisedEntityIds(
entity_uuid.trashed = 0
and (entity.current_revision_id is null or
entity.current_revision_id < revision.max_revision_id)
order by max_revision_id
`,
[userId, userId],
)
Expand Down

0 comments on commit ea6b2de

Please sign in to comment.