Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Florin H committed Oct 13, 2023
1 parent 0d2b86e commit 7ca7cc0
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 358 deletions.
77 changes: 0 additions & 77 deletions api/prisma/convertResearchTopics.ts

This file was deleted.

90 changes: 0 additions & 90 deletions api/prisma/removeResearchTopicProblems.ts

This file was deleted.

7 changes: 0 additions & 7 deletions api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,6 @@ functions:
path: ${self:custom.versions.v1}/publications/{id}/pdf
method: GET
cors: true
getResearchTopics:
handler: src/components/publication/routes.getResearchTopics
events:
- http:
path: ${self:custom.versions.v1}/publications/research-topics
method: GET
cors: true
getPublicationTopics:
handler: src/components/publication/routes.getPublicationTopics
events:
Expand Down
6 changes: 3 additions & 3 deletions api/src/components/coauthor/__tests__/createCoAuthor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,12 @@ describe('create coauthor', () => {

test('Co-author email is converted to lower case on save', async () => {
await testUtils.agent
.put('/publications/publication-data-draft/coauthors')
.put('/publication-versions/publication-data-draft-v1/coauthors')
.query({ apiKey: '123456789' })
.send([
{
id: createId(),
publicationId: 'publication-problem-draft',
publicationVersionId: 'publication-problem-draft-v1',
email: 'MULTIcaseAddress@emailtest.COM',
linkedUser: null,
approvalRequested: false,
Expand All @@ -143,7 +143,7 @@ describe('create coauthor', () => {
]);

const coAuthors = await testUtils.agent
.get('/publications/publication-data-draft/coauthors')
.get('/publication-versions/publication-data-draft-v1/coauthors')
.query({ apiKey: '123456789' });

expect(coAuthors.body.length).toEqual(2); // corresponding author and this new one
Expand Down
23 changes: 0 additions & 23 deletions api/src/components/publication/__tests__/getResearchTopics.test.ts

This file was deleted.

10 changes: 0 additions & 10 deletions api/src/components/publication/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,16 +202,6 @@ export const getPDF = async (
: response.json(200, { pdfUrl });
};

export const getResearchTopics = async (): Promise<I.JSONResponse> => {
try {
const researchTopics = await publicationService.getResearchTopics();

return response.json(200, researchTopics);
} catch (error) {
return response.json(500, { message: 'Unknown server error.' });
}
};

export const updateTopics = async (
event: I.AuthenticatedAPIRequest<
I.UpdatePublicationTopicsRequestBody,
Expand Down
4 changes: 0 additions & 4 deletions api/src/components/publication/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export const getPDF = middy(publicationController.getPDF)
.use(middleware.httpJsonBodyParser())
.use(middleware.validator(publicationSchema.getPDF, 'pathParameters'));

export const getResearchTopics = middy(publicationController.getResearchTopics).use(
middleware.doNotWaitForEmptyEventLoop({ runOnError: true, runOnBefore: true, runOnAfter: true })
);

export const updateTopics = middy(publicationController.updateTopics)
.use(middleware.doNotWaitForEmptyEventLoop({ runOnError: true, runOnBefore: true, runOnAfter: true }))
.use(middleware.httpJsonBodyParser())
Expand Down
124 changes: 1 addition & 123 deletions api/src/components/publication/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as referenceService from 'reference/service';
import * as Helpers from 'lib/helpers';
import { Browser, launch } from 'puppeteer-core';
import { PutObjectCommand } from '@aws-sdk/client-s3';
import { Prisma } from '@prisma/client';

export const isIdInUse = async (id: string) => {
const publication = await client.prisma.publication.count({
Expand Down Expand Up @@ -922,129 +923,6 @@ export const generatePDF = async (publicationVersion: I.PublicationVersion): Pro
}
};

export const getResearchTopics = async () => {
const publications = await client.prisma.publication.findMany({
where: {
type: 'PROBLEM',
OR: [
{
id: {
equals: 'why' // god problem will be converted to a god topic
}
},
{
versions: {
some: {
isLatestVersion: true,
content: {
contains: 'This is an automatically-generated topic'
}
}
}
}
],
References: {
none: {}
},
...additionalFilters,
versions: {
some: {
createdBy: 'octopus',
isLatestVersion: true,
References: {
none: {}
}
}
}
},
include: {
versions: {
where: {
isLatestVersion: true
},
include: {
user: {
select: {
id: true,
firstName: true,
lastName: true,
orcid: true
}
}
}
},
linkedTo: {
select: {
id: true,
publicationToRef: {
select: {
id: true,
type: true,
doi: true,
versions: {
select: {
user: {
select: {
id: true,
firstName: true,
lastName: true,
orcid: true
}
},
title: true,
publishedDate: true,
currentStatus: true,
description: true,
keywords: true
}
}
}
}
}
},
linkedFrom: {
select: {
id: true,
publicationFromRef: {
select: {
id: true,
type: true,
doi: true,
versions: {
select: {
user: {
select: {
id: true,
firstName: true,
lastName: true,
orcid: true
}
},
title: true,
publishedDate: true,
currentStatus: true,
description: true,
keywords: true
}
}
}
}
}
},
PublicationBookmarks: true
}
});

// Merge versioned data into the publication records
const mergedPublications = publications.map((publication) => {
const currentVersion = publication.versions[0];

return { ...currentVersion, ...publication };
});

return mergedPublications;
};

// Overwrite existing topics with those whose IDs were passed.
export const updateTopics = async (id: string, topics: string[]) => {
// Format topics in a way that prisma can understand.
Expand Down
Loading

0 comments on commit 7ca7cc0

Please sign in to comment.