Skip to content

Commit

Permalink
Merge pull request #1086 from serlo/remove-solutions
Browse files Browse the repository at this point in the history
refactor(schema): remove `Solution` type
  • Loading branch information
kulla authored Nov 11, 2023
2 parents b596fe3 + f969a75 commit 85fefe5
Show file tree
Hide file tree
Showing 30 changed files with 99 additions and 715 deletions.
16 changes: 8 additions & 8 deletions __fixtures__/notification.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {
article,
articleRevision,
exercise,
solution,
taxonomyTermCurriculumTopic,
taxonomyTermRoot,
taxonomyTermSubject,
user,
comment,
coursePage,
course,
} from './uuid'
import { Model } from '~/internals/graphql'
import { castToUuid, NotificationEventType } from '~/model/decoder'
Expand Down Expand Up @@ -69,9 +69,9 @@ export const createEntityLinkNotificationEvent: Model<'CreateEntityLinkNotificat
instance: Instance.De,
date: '2014-03-01T20:45:56Z',
actorId: user.id,
objectId: solution.id,
parentId: exercise.id,
childId: solution.id,
objectId: coursePage.id,
parentId: course.id,
childId: coursePage.id,
}

export const removeEntityLinkNotificationEvent: Model<'RemoveEntityLinkNotificationEvent'> =
Expand All @@ -81,9 +81,9 @@ export const removeEntityLinkNotificationEvent: Model<'RemoveEntityLinkNotificat
instance: Instance.De,
date: '2014-03-01T20:45:56Z',
actorId: user.id,
objectId: solution.id,
parentId: exercise.id,
childId: solution.id,
objectId: coursePage.id,
parentId: course.id,
childId: coursePage.id,
}

export const createEntityRevisionNotificationEvent: Model<'CreateEntityRevisionNotificationEvent'> =
Expand Down
1 change: 0 additions & 1 deletion __fixtures__/uuid/exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export const exercise: Model<'Exercise'> = {
currentRevisionId: castToUuid(29638),
revisionIds: [29638].map(castToUuid),
licenseId: license.id,
solutionId: castToUuid(29648),
taxonomyTermIds: [5].map(castToUuid),
canonicalSubjectId: castToUuid(5),
}
Expand Down
1 change: 0 additions & 1 deletion __fixtures__/uuid/grouped-exercise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export const groupedExercise: Model<'GroupedExercise'> = {
currentRevisionId: castToUuid(2220),
revisionIds: [2220].map(castToUuid),
licenseId: license.id,
solutionId: castToUuid(29648),
parentId: exerciseGroup.id,
canonicalSubjectId: castToUuid(5),
}
Expand Down
1 change: 0 additions & 1 deletion __fixtures__/uuid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export * from './exercise-group'
export * from './event'
export * from './grouped-exercise'
export * from './page'
export * from './solution'
export * from './taxonomy-term'
export * from './thread'
export * from './user'
Expand Down
45 changes: 0 additions & 45 deletions __fixtures__/uuid/solution.ts

This file was deleted.

4 changes: 0 additions & 4 deletions __tests-pacts__/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import {
page,
pageRevision,
pageRevision2,
solution,
solutionRevision,
taxonomyTermCurriculumTopic,
taxonomyTermRoot,
taxonomyTermSubject,
Expand Down Expand Up @@ -98,8 +96,6 @@ const uuids = [
groupedExerciseRevision,
page,
pageRevision,
solution,
solutionRevision,
taxonomyTermRoot,
taxonomyTermSubject,
taxonomyTermCurriculumTopic,
Expand Down
16 changes: 5 additions & 11 deletions __tests__/schema/entity/deleted-entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import gql from 'graphql-tag'
import {
article as baseArticle,
coursePage as baseCoursePage,
solution as baseSolution,
} from '../../../__fixtures__'
import { given, Client } from '../../__utils__'
import { Instance } from '~/types'
Expand All @@ -27,10 +26,9 @@ const query = new Client().prepareQuery({

const coursePage = { ...baseCoursePage, instance: Instance.En }
const article = { ...baseArticle, date: '2015-03-01T20:45:56Z' }
const solution = { ...baseSolution, date: '2016-03-01T20:45:56Z' }

beforeEach(() => {
given('DeletedEntitiesQuery').for(article, coursePage, solution)
given('DeletedEntitiesQuery').for(article, coursePage)
})

test('returns deleted entities', async () => {
Expand All @@ -46,10 +44,6 @@ test('returns deleted entities', async () => {
dateOfDeletion: coursePage.date,
entity: { id: coursePage.id },
},
{
dateOfDeletion: solution.date,
entity: { id: solution.id },
},
],
},
},
Expand All @@ -74,8 +68,8 @@ test('paginates with `after` parameter { entityId, dateOfDeletion}, ', async ()
.withVariables({
after: Buffer.from(
JSON.stringify({
id: article.id,
dateOfDeletion: article.date,
id: coursePage.id,
dateOfDeletion: coursePage.date,
}),
).toString('base64'),
})
Expand All @@ -84,8 +78,8 @@ test('paginates with `after` parameter { entityId, dateOfDeletion}, ', async ()
deletedEntities: {
nodes: [
{
dateOfDeletion: solution.date,
entity: { id: solution.id },
dateOfDeletion: article.date,
entity: { id: article.id },
},
],
},
Expand Down
59 changes: 25 additions & 34 deletions __tests__/schema/entity/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
exercise,
exerciseGroup,
groupedExercise,
solution,
taxonomyTermSubject,
taxonomyTermRoot,
user,
Expand All @@ -23,11 +22,10 @@ import {
exerciseRevision,
exerciseGroupRevision,
groupedExerciseRevision,
solutionRevision,
videoRevision,
} from '../../../__fixtures__'
import { given, Client, nextUuid, getTypenameAndId } from '../../__utils__'
import { autoreviewTaxonomyIds } from '~/config/autoreview-taxonomies'
import { autoreviewTaxonomyIds } from '~/config'
import { Model } from '~/internals/graphql'
import { DatabaseLayer } from '~/model'
import { castToUuid, DiscriminatorType, EntityType } from '~/model/decoder'
Expand Down Expand Up @@ -73,7 +71,6 @@ const fieldKeys: Record<
[EntityType.Exercise]: ['content'],
[EntityType.ExerciseGroup]: ['cohesive', 'content'],
[EntityType.GroupedExercise]: ['content'],
[EntityType.Solution]: ['content'],
[EntityType.Video]: ['title', 'content', 'url'],
}
const entities = [
Expand All @@ -85,7 +82,6 @@ const entities = [
exercise,
exerciseGroup,
groupedExercise,
solution,
video,
]

Expand All @@ -103,11 +99,9 @@ class EntitySetTestCase {
}

get inputName() {
return [
EntityType.Exercise,
EntityType.GroupedExercise,
EntityType.Solution,
].includes(this.entityType)
return [EntityType.Exercise, EntityType.GroupedExercise].includes(
this.entityType,
)
? 'SetGenericEntityInput'
: `Set${this.entityType}Input`
}
Expand All @@ -118,8 +112,6 @@ class EntitySetTestCase {
return course
case EntityType.GroupedExercise:
return exerciseGroup
case EntityType.Solution:
return exercise
default:
return taxonomyTermSubject
}
Expand Down Expand Up @@ -166,8 +158,6 @@ class EntitySetTestCase {
return exerciseGroupRevision
case EntityType.GroupedExercise:
return groupedExerciseRevision
case EntityType.Solution:
return solutionRevision
case EntityType.Video:
return videoRevision
}
Expand Down Expand Up @@ -512,7 +502,7 @@ test('uses default license of the instance', async () => {
given('EntityCreateMutation')
.withPayload({
userId: 1,
entityType: EntityType.Solution,
entityType: EntityType.Exercise,
input: {
changes: 'changes',
licenseId: 9,
Expand All @@ -523,14 +513,14 @@ test('uses default license of the instance', async () => {
parentId: exerciseEn.id,
},
})
.returns(solution)
.returns(exercise)

await new Client({ userId: user.id })
.prepareQuery({
query: gql`
mutation ($input: SetGenericEntityInput!) {
entity {
setSolution(input: $input) {
setExercise(input: $input) {
success
}
}
Expand All @@ -545,7 +535,7 @@ test('uses default license of the instance', async () => {
parentId: exerciseEn.id,
content: 'Hello World',
})
.shouldReturnData({ entity: { setSolution: { success: true } } })
.shouldReturnData({ entity: { setExercise: { success: true } } })
})

describe('Autoreview entities', () => {
Expand All @@ -559,11 +549,11 @@ describe('Autoreview entities', () => {

const mutation = new Client({ userId: user.id }).prepareQuery({
query: gql`
mutation set($input: SetGenericEntityInput!) {
mutation ($input: SetGenericEntityInput!) {
entity {
setSolution(input: $input) {
setExercise(input: $input) {
record {
... on Solution {
... on Exercise {
currentRevision {
id
}
Expand All @@ -575,24 +565,25 @@ describe('Autoreview entities', () => {
`,
})

const oldRevisionId = solution.currentRevisionId
const oldRevisionId = exercise.currentRevisionId
const newRevisionId = castToUuid(789)

const entity = {
...solution,
parentId: groupedExercise.id,
const taxonomy = { ...taxonomyTermSubject, id: castToUuid(106082) }
const entity: typeof exercise = {
...exercise,
currentRevisionId: oldRevisionId,
taxonomyTermIds: [taxonomy.id],
}
const newRevision = { ...solutionRevision, id: newRevisionId }

const newRevision = { ...exerciseRevision, id: newRevisionId }

beforeEach(() => {
given('UuidQuery').for(
entity,
groupedExercise,
solutionRevision,
exerciseRevision,
article,
{ ...exerciseGroup, taxonomyTermIds: [106082].map(castToUuid) },
{ ...taxonomyTermSubject, id: castToUuid(106082) },
taxonomy,
)

given('EntityAddRevisionMutation').isDefinedBy((req, res, ctx) => {
Expand Down Expand Up @@ -624,17 +615,17 @@ describe('Autoreview entities', () => {
.withInput({ ...input, entityId: entity.id })
.shouldReturnData({
entity: {
setSolution: { record: { currentRevision: { id: newRevisionId } } },
setExercise: { record: { currentRevision: { id: newRevisionId } } },
},
})
})

test('when a new entity is created', async () => {
await mutation
.withInput({ ...input, parentId: groupedExercise.id })
.withInput({ ...input, parentId: taxonomy.id })
.shouldReturnData({
entity: {
setSolution: { record: { currentRevision: { id: newRevisionId } } },
setExercise: { record: { currentRevision: { id: newRevisionId } } },
},
})
})
Expand All @@ -645,7 +636,7 @@ describe('Autoreview entities', () => {
castToUuid,
)
given('UuidQuery').for(
{ ...exerciseGroup, taxonomyTermIds },
{ ...exercise, taxonomyTermIds },
{ ...taxonomyTermSubject, id: castToUuid(autoreviewTaxonomyIds[0]) },
taxonomyTermRoot,
)
Expand All @@ -654,7 +645,7 @@ describe('Autoreview entities', () => {
.withInput({ ...input, entityId: entity.id })
.shouldReturnData({
entity: {
setSolution: { record: { currentRevision: { id: oldRevisionId } } },
setExercise: { record: { currentRevision: { id: oldRevisionId } } },
},
})
})
Expand Down
Loading

0 comments on commit 85fefe5

Please sign in to comment.