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

refactor(event): Update after simplification of event tables #1557

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
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
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 @@ -97,7 +97,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
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 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-simplify-taxonomy-tables
image: eu.gcr.io/serlo-shared/serlo-mysql-database:prerelease-entityfield-coursepage-event-taxonomy
platform: linux/x86_64
pull_policy: always
ports:
Expand Down
Loading
Loading