diff --git a/__tests__/schema/uuid/user.ts b/__tests__/schema/uuid/user.ts index b8505ee54..ec35c3af2 100644 --- a/__tests__/schema/uuid/user.ts +++ b/__tests__/schema/uuid/user.ts @@ -18,14 +18,11 @@ import { givenSpreadsheet, hasInternalServerError, nextUuid, - returnsJson, - returnsMalformedJson, given, Client, } from '../../__utils__' import { Model } from '~/internals/graphql' import { MajorDimension } from '~/model' -import { castToUuid } from '~/model/decoder' import { Instance } from '~/types' const client = new Client() @@ -559,133 +556,6 @@ describe('User', () => { }) }) -describe('endpoint activeAuthors', () => { - test('returns list of active authors', async () => { - given('ActiveAuthorsQuery').returns([user.id, user2.id]) - - await expectUserIds({ endpoint: 'activeAuthors', ids: [user.id, user2.id] }) - }) - - test('returns only users', async () => { - given('ActiveAuthorsQuery').returns([user.id, article.id]) - given('UuidQuery').for(article) - - await expectUserIds({ endpoint: 'activeAuthors', ids: [user.id] }) - await assertErrorEvent({ errorContext: { invalidElements: [article] } }) - }) -}) - -describe('endpoint activeReviewers', () => { - test('returns list of active reviewers', async () => { - given('ActiveReviewersQuery').returns([user.id, user2.id]) - - await expectUserIds({ - endpoint: 'activeReviewers', - ids: [user.id, user2.id], - }) - }) - - test('returns only users', async () => { - given('ActiveReviewersQuery').returns([user.id, article.id]) - given('UuidQuery').for(article) - - await expectUserIds({ endpoint: 'activeReviewers', ids: [user.id] }) - await assertErrorEvent({ errorContext: { invalidElements: [article] } }) - }) -}) - -describe('endpoint activeDonors', () => { - test('returns list of users', async () => { - givenActiveDonors([user, user2]) - given('UuidQuery').for(user2) - - await expectUserIds({ endpoint: 'activeDonors', ids: [user.id, user2.id] }) - }) - - test('returned list only contains user', async () => { - givenActiveDonors([user, article]) - given('UuidQuery').for(article) - - await expectUserIds({ endpoint: 'activeDonors', ids: [user.id] }) - await assertErrorEvent({ errorContext: { invalidElements: [article] } }) - }) - - describe('parser', () => { - test('removes entries which are no valid uuids', async () => { - givenActiveDonorsSpreadsheet([['Header', '23', 'foo', '-1', '', '1.5']]) - - await expectUserIds({ endpoint: 'activeDonors', ids: [23] }) - await assertErrorEvent({ - message: 'invalid entry in activeDonorSpreadsheet', - errorContext: { invalidElements: ['foo', '-1', '', '1.5'] }, - }) - }) - - test('cell entries are trimmed of leading and trailing whitespaces', async () => { - givenActiveDonorsSpreadsheet([['Header', ' 10 ', ' 20']]) - - await expectUserIds({ endpoint: 'activeDonors', ids: [10, 20] }) - }) - - describe('returns empty list', () => { - test('when spreadsheet is empty', async () => { - givenActiveDonorsSpreadsheet([[]]) - - await expectUserIds({ endpoint: 'activeDonors', ids: [] }) - }) - - test('when spreadsheet api responds with invalid json data', async () => { - givenSpreadheetApi(returnsJson({ json: {} })) - - await expectUserIds({ endpoint: 'activeDonors', ids: [] }) - await assertErrorEvent() - }) - - test('when spreadsheet api responds with malformed json', async () => { - givenSpreadheetApi(returnsMalformedJson()) - - await expectUserIds({ endpoint: 'activeDonors', ids: [] }) - await assertErrorEvent() - }) - - test('when spreadsheet api has an internal server error', async () => { - givenSpreadheetApi(hasInternalServerError()) - - await expectUserIds({ endpoint: 'activeDonors', ids: [] }) - await assertErrorEvent() - }) - }) - }) -}) - -async function expectUserIds({ - endpoint, - ids, -}: { - endpoint: 'activeReviewers' | 'activeAuthors' | 'activeDonors' - ids: number[] -}) { - ids.map(castToUuid).forEach((id) => given('UuidQuery').for({ ...user, id })) - const nodes = ids.map((id) => { - return { __typename: 'User', id } - }) - - await new Client() - .prepareQuery({ - query: gql` - query { - ${endpoint} { - nodes { - __typename - id - } - } - } - `, - }) - .shouldReturnData({ [endpoint]: { nodes } }) -} - function givenActiveDonors(users: Model<'AbstractUuid'>[]) { const values = [['Header', ...users.map((user) => user.id.toString())]] givenActiveDonorsSpreadsheet(values) diff --git a/packages/server/src/schema/uuid/user/resolvers.ts b/packages/server/src/schema/uuid/user/resolvers.ts index 0a668100e..3c4eaf96b 100644 --- a/packages/server/src/schema/uuid/user/resolvers.ts +++ b/packages/server/src/schema/uuid/user/resolvers.ts @@ -20,59 +20,27 @@ import { createNamespace, generateRole, isGlobalRole, - LegacyQueries, - Model, Mutations, Queries, TypeResolvers, } from '~/internals/graphql' -import { - DiscriminatorType, - EntityDecoder, - RevisionDecoder, - UserDecoder, -} from '~/model/decoder' +import { EntityDecoder, RevisionDecoder, UserDecoder } from '~/model/decoder' import { CellValues, MajorDimension } from '~/model/google-spreadsheet-api' import { getPermissionsForRole, getRolesWithInheritance, } from '~/schema/authorization/roles' import { resolveScopedRoles } from '~/schema/authorization/utils' -import { ConnectionPayload } from '~/schema/connection/types' import { resolveConnection } from '~/schema/connection/utils' import { resolveEvents } from '~/schema/notification/resolvers' import { createThreadResolvers } from '~/schema/thread/utils' import { createUuidResolvers } from '~/schema/uuid/abstract-uuid/utils' import { Instance, User } from '~/types' -export const resolvers: LegacyQueries< - 'activeAuthors' | 'activeReviewers' | 'activeDonors' -> & - TypeResolvers & +export const resolvers: TypeResolvers & Queries<'user'> & Mutations<'user'> = { Query: { - async activeAuthors(_parent, payload, context) { - return resolveUserConnectionFromIds({ - ids: await context.dataSources.model.serlo.getActiveAuthorIds(), - payload, - context, - }) - }, - async activeDonors(_parent, payload, context) { - return resolveUserConnectionFromIds({ - ids: await activeDonorIDs(context), - payload, - context, - }) - }, - async activeReviewers(_parent, payload, context) { - return resolveUserConnectionFromIds({ - ids: await context.dataSources.model.serlo.getActiveReviewerIds(), - payload, - context, - }) - }, user: createNamespace(), }, UserQuery: { @@ -483,34 +451,6 @@ export const resolvers: LegacyQueries< }, } -async function resolveUserConnectionFromIds({ - ids, - payload, - context, -}: { - ids: number[] - payload: ConnectionPayload - context: Context -}) { - const uuids = await Promise.all( - ids.map(async (id) => context.dataSources.model.serlo.getUuid({ id })), - ) - const users = assertAll({ - assertion(uuid: Model<'AbstractUuid'> | null): uuid is Model<'User'> { - return uuid !== null && uuid.__typename == DiscriminatorType.User - }, - error: new Error('Invalid user found'), - })(uuids) - - return resolveConnection({ - nodes: users, - payload, - createCursor(node) { - return node.id.toString() - }, - }) -} - async function activeDonorIDs({ dataSources }: Context) { return F.pipe( await dataSources.model.googleSpreadsheetApi.getValues({ diff --git a/packages/server/src/schema/uuid/user/types.graphql b/packages/server/src/schema/uuid/user/types.graphql index b496ad653..f0e4d94e8 100644 --- a/packages/server/src/schema/uuid/user/types.graphql +++ b/packages/server/src/schema/uuid/user/types.graphql @@ -55,24 +55,6 @@ type User implements AbstractUuid & ThreadAware { } extend type Query { - activeAuthors( - after: String - before: String - first: Int - last: Int - ): UserConnection! - activeDonors( - after: String - before: String - first: Int - last: Int - ): UserConnection! - activeReviewers( - after: String - before: String - first: Int - last: Int - ): UserConnection! user: UserQuery! } diff --git a/packages/server/src/types.ts b/packages/server/src/types.ts index 1f53cb2c2..8bd405e8c 100644 --- a/packages/server/src/types.ts +++ b/packages/server/src/types.ts @@ -1783,9 +1783,6 @@ export type PageRevisionCursor = { export type Query = { __typename?: 'Query'; - activeAuthors: UserConnection; - activeDonors: UserConnection; - activeReviewers: UserConnection; ai: AiQuery; authorization: Scalars['JSON']['output']; entity?: Maybe; @@ -1804,30 +1801,6 @@ export type Query = { }; -export type QueryActiveAuthorsArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - -export type QueryActiveDonorsArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - -export type QueryActiveReviewersArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - export type QueryEventsArgs = { actorId?: InputMaybe; after?: InputMaybe; @@ -4322,9 +4295,6 @@ export type PageRevisionCursorResolvers = { - activeAuthors?: Resolver>; - activeDonors?: Resolver>; - activeReviewers?: Resolver>; ai?: Resolver; authorization?: Resolver; entity?: Resolver, ParentType, ContextType>; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 2ca36b5c7..c08d868b6 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -1779,9 +1779,6 @@ export type PageRevisionCursor = { export type Query = { __typename?: 'Query'; - activeAuthors: UserConnection; - activeDonors: UserConnection; - activeReviewers: UserConnection; ai: AiQuery; authorization: Scalars['JSON']['output']; entity?: Maybe; @@ -1800,30 +1797,6 @@ export type Query = { }; -export type QueryActiveAuthorsArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - -export type QueryActiveDonorsArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - -export type QueryActiveReviewersArgs = { - after?: InputMaybe; - before?: InputMaybe; - first?: InputMaybe; - last?: InputMaybe; -}; - - export type QueryEventsArgs = { actorId?: InputMaybe; after?: InputMaybe;