Skip to content

Commit

Permalink
Merge pull request #1561 from serlo/DNmHL-kulla-2024-06-09-12-05
Browse files Browse the repository at this point in the history
refactor(taxonomy): Update after simplify taxonomy tables
  • Loading branch information
hugotiburtino authored Jun 14, 2024
2 parents ee94b47 + ba3e53b commit db43ee3
Show file tree
Hide file tree
Showing 23 changed files with 202 additions and 318 deletions.
5 changes: 0 additions & 5 deletions __fixtures__/uuid/taxonomy-term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const taxonomyTermRoot: Model<'TaxonomyTerm'> = {
description: null,
weight: 1,
parentId: null,
taxonomyId: 1,
childrenIds: [5],
}

Expand All @@ -28,7 +27,6 @@ export const taxonomyTermSubject: Model<'TaxonomyTerm'> = {
description: null,
weight: 2,
parentId: taxonomyTermRoot.id,
taxonomyId: 3,
childrenIds: [16048],
}

Expand All @@ -42,7 +40,6 @@ export const taxonomyTermCurriculumTopic: Model<'TaxonomyTerm'> = {
name: 'name',
description: 'description',
weight: 3,
taxonomyId: 11,
parentId: taxonomyTermSubject.id,
childrenIds: [1855],
}
Expand All @@ -57,7 +54,6 @@ export const taxonomyTermTopic: Model<'TaxonomyTerm'> = {
name: 'Geometrie',
description: null,
weight: 6,
taxonomyId: 4,
parentId: 5,
childrenIds: [
23453, 1454, 1394, 24518, 1380, 24410, 24422, 1381, 1383, 1300, 1413,
Expand All @@ -74,7 +70,6 @@ export const taxonomyTermTopicFolder: Model<'TaxonomyTerm'> = {
name: 'Aufgaben zu einfachen Potenzen',
description: '',
weight: 1,
taxonomyId: 9,
parentId: 1288,
childrenIds: [10385, 6925, 6921, 6933, 6917, 7085],
}
11 changes: 8 additions & 3 deletions __tests__/__utils__/assertions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,16 @@ export async function assertErrorEvent(args?: {

if (args?.errorContext !== undefined) {
for (const contextName in args.errorContext) {
const contextValue = event.contexts?.error?.[contextName]
const contextValueString = event.contexts?.error?.[contextName]
const contextValue = destringifyProperties(contextValueString)
const targetValue = args.errorContext[contextName]

if (!R.equals(destringifyProperties(contextValue), targetValue))
return false
if (typeof targetValue === 'object' && targetValue !== null) {
if (!R.equals(R.pick(R.keys(targetValue), contextValue), targetValue))
return false
} else {
if (contextValue !== targetValue) return false
}
}
}

Expand Down
1 change: 0 additions & 1 deletion __tests__/__utils__/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ export const taxonomyTermQuery = new Client().prepareQuery({
name
description
weight
taxonomyId
path {
id
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schema/entity/set-abstract-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ beforeEach(async () => {
// create taxonomy Term 106082
await databaseForTests.mutate('update uuid set id = 106082 where id = 35607')
await databaseForTests.mutate(
'update term_taxonomy set id = 106082 where id = 35607',
'update taxonomy set id = 106082 where id = 35607',
)
})

Expand Down
17 changes: 2 additions & 15 deletions __tests__/schema/event-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ test('adds a notification', async () => {

expect(
await databaseForTests.fetchAll(
'select * from notification_event where event_log_id = ?',
'select * from notification_event where event_id = ?',
[lastEvent.id],
),
).not.toHaveLength(0)
Expand All @@ -100,19 +100,6 @@ test('fails if object does not exist', async () => {
).rejects.toThrow()
})

test('fails if name from parameters is invalid', async () => {
const initialEventsNumber = await getEventsNumber()

await global.databaseForTests.mutate(
'delete from event_parameter_name where name = "discussion"',
)

await expect(createEvent(basePayload, getContext())).rejects.toThrow()

const finalEventsNumber = await getEventsNumber()
expect(finalEventsNumber).toEqual(initialEventsNumber)
})

test('fails if uuid number in parameters does not exist', async () => {
await expect(
createEvent({ ...basePayload, threadId: 40000 }, getContext()),
Expand Down Expand Up @@ -309,7 +296,7 @@ function getApiResult(event: Record<string, unknown>): Record<string, unknown> {
async function getEventsNumber() {
return (
await global.databaseForTests.fetchOne<{ n: number }>(
'SELECT count(*) AS n FROM event_log',
'SELECT count(*) AS n FROM event',
)
).n
}
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schema/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('query endpoint "events"', () => {
test('with filter "objectId"', async () => {
await query.withVariables({ first: 1, objectId: 1855 }).shouldReturnData({
events: {
nodes: [{ __typename: 'CreateEntityNotificationEvent', id: 1198 }],
nodes: [{ __typename: 'CheckoutRevisionNotificationEvent', id: 77030 }],
},
})
})
Expand Down
14 changes: 0 additions & 14 deletions __tests__/schema/taxonomy-term/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,6 @@ describe('creates a new taxonomy term', () => {
})
})

test('does not fail when there are duplicated taxonomy entries', async () => {
// In the database layer there was a bug to created multiple duplicated
// taxonomy entries (which is currently not in the DB container)
// This test can be deleted after https://github.com/serlo/db-migrations/issues/346

await databaseForTests.mutate(
`insert into taxonomy (type_id, instance_id) values (11, 1)`,
)

await mutation.shouldReturnData({
taxonomyTerm: { create: { success: true } },
})
})

test('cache of parent is updated', async () => {
const query = new Client().prepareQuery({
query: gql`
Expand Down
12 changes: 7 additions & 5 deletions __tests__/schema/user/delete-bots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { createHash } from 'crypto'
import gql from 'graphql-tag'
import { HttpResponse, ResponseResolver, http } from 'msw'

import { article, user, user2 } from '../../../__fixtures__'
import { article, user } from '../../../__fixtures__'
import {
given,
Client,
Query,
returnsJson,
assertErrorEvent,
assertNoErrorEvents,
given,
returnsJson,
userQuery,
} from '../../__utils__'

Expand Down Expand Up @@ -137,11 +137,13 @@ describe('community chat', () => {
returnsJson({ json: { success: false, errorType: 'unknown' } }),
)

await mutation.withInput({ botIds: [user2.id] }).execute()
await mutation
.withInput({ botIds: input.botIds.slice(1) })
.shouldReturnData({ user: { deleteBots: { success: true } } })

await assertErrorEvent({
message: 'Cannot delete a user from community.serlo.org',
errorContext: { user: user2 },
errorContext: { user: { id: input.botIds[1] } },
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/schema/uuid/entity-revision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test('Uuid query for an entity revision', async () => {
repository: { id: 35295 },
title: '"falsche Freunde"',
content:
'{"plugin":"rows","state":[{"plugin":"text","state":[{"type":"p","children":[{"text":"wip"}]}],"id":"8abdb955-fa42-442d-87a8-91bfae603101"}],"id":"e5dd1162-7e55-4b1c-aacd-acb267c290ee"}',
'{"plugin":"rows","state":[{"plugin":"text","state":[{"type":"p","children":[{"text":"wip"}]}],"id":"7165fed8-d729-45fd-a28c-8ea7c2622953"}],"id":"3b4326f6-88c6-4da8-9bea-f0eb4aa5407a"}',
changes: '',
metaTitle: '',
metaDescription: '',
Expand Down
3 changes: 0 additions & 3 deletions __tests__/schema/uuid/taxonomy-term.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ test('TaxonomyTerm root', async () => {
name: 'Root',
description: null,
weight: 0,
taxonomyId: 1,
path: [],
parent: null,
children: {
Expand Down Expand Up @@ -55,7 +54,6 @@ test('TaxonomyTerm subject', async () => {
name: 'Chemie',
description: '',
weight: 17,
taxonomyId: 3,
path: [],
parent: { id: 3 },
children: {
Expand Down Expand Up @@ -87,7 +85,6 @@ test('TaxonomyTerm exerciseFolder', async () => {
name: 'Example topic folder',
description: '',
weight: 1,
taxonomyId: 19,
path: [{ id: 23590 }, { id: 23593 }, { id: 35559 }, { id: 35560 }],
parent: {
id: 35560,
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
ports:
- '6379:6379'
mysql:
image: eu.gcr.io/serlo-shared/serlo-mysql-database:prerelease-merge-course-pages-into-courses.2
image: eu.gcr.io/serlo-shared/serlo-mysql-database:prerelease-entityfield-coursepage-event-taxonomy
platform: linux/x86_64
pull_policy: always
ports:
Expand Down
1 change: 0 additions & 1 deletion packages/server/src/model/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ export const TaxonomyTermDecoder = t.exact(
weight: t.number,
childrenIds: t.array(t.number),
parentId: t.union([t.number, t.null]),
taxonomyId: t.number,
}),
t.partial({
description: t.union([t.string, t.null]),
Expand Down
Loading

0 comments on commit db43ee3

Please sign in to comment.