Skip to content

Commit

Permalink
ASAP-686 CRN Public API changes (#4408)
Browse files Browse the repository at this point in the history
* ASAP-686 CRN Public API changes

* empty to trigger ci 2
  • Loading branch information
gabiayako authored Oct 8, 2024
1 parent 073a027 commit 043f236
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
ResearchOutputsOrder,
RichTextFromQuery,
} from '@asap-hub/contentful';
import { cleanArray, parseUserDisplayName } from '@asap-hub/server-common';
import { parseUserDisplayName } from '@asap-hub/server-common';
import { isSharingStatus } from '../transformers/research-output';
import {
CreateResearchOutputOptions,
Expand Down Expand Up @@ -333,9 +333,9 @@ const parseGraphQLResearchOutput = (
return {
id: researchOutputs.sys.id,
title: researchOutputs.title || '',
researchTheme: researchOutputs.researchTheme
? cleanArray(researchOutputs.researchTheme)
: [],
researchTheme: (researchOutputs.teamsCollection?.items || [])
.map((teamItem) => teamItem?.researchTheme?.name)
.filter((item): item is string => item !== undefined),
description: researchOutputs.description
? parseRichText(researchOutputs.description as RichTextFromQuery)
: undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,12 @@ export const parseContentfulGraphQlUsers = (item: UserItem): UserDataObject => {
interestGroups,
onboarded: typeof item.onboarded === 'boolean' ? item.onboarded : undefined,
email: item.email ?? '',
researchTheme: item.researchTheme ? cleanArray(item.researchTheme) : [],
researchTheme: teamsCollection
.map((teamItem) => teamItem.team?.researchTheme?.name)
.filter(
(researchThemeName): researchThemeName is string =>
researchThemeName !== undefined,
),
contactEmail: item.contactEmail ?? undefined,
firstName: item.firstName ?? '',
middleName: item.middleName || undefined,
Expand Down Expand Up @@ -650,6 +655,7 @@ const parseLeadersToInterestGroups = (
id: group?.sys.id,
active: group?.active,
name: group?.name,
role: leader.role,
} as InterestGroupMembership);

return interestGroups;
Expand Down
1 change: 1 addition & 0 deletions apps/crn-server/src/routes/public/user.route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const mapUserToPublicUser = (user: UserResponse): PublicUserResponse => ({
institution: user.institution,
interestGroups: user.interestGroups.map((ig) => ({
name: ig.name,
role: ig.role,
})),
labs: user.labs,
researchTheme: user.researchTheme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ describe('Research Outputs Data Provider', () => {

test('Should default missing research theme to an empty array', async () => {
const researchOutputs = getContentfulResearchOutputGraphqlResponse();
researchOutputs.researchTheme = null;
researchOutputs.teamsCollection!.items[0]!.researchTheme = null;
contentfulGraphqlClientMock.request.mockResolvedValueOnce({
researchOutputs,
});
Expand Down Expand Up @@ -707,36 +707,6 @@ describe('Research Outputs Data Provider', () => {
]);
});

test('Should return the research output without the team', async () => {
const researchOutputs = getContentfulResearchOutputGraphqlResponse();
researchOutputs.teamsCollection!.items = [];
researchOutputs.workingGroup = { sys: { id: '1' }, title: 'wg' };
researchOutputs.researchTheme = [
'PD Functional Genomics',
'Neuro-Immune Interactions',
];
contentfulGraphqlClientMock.request.mockResolvedValueOnce({
researchOutputs,
});

const result = await researchOutputDataProvider.fetchById('1');

const expectedResult = getResearchOutputDataObject();
expectedResult.usageNotesMD = researchOutputs.usageNotes as string;
expectedResult.usageNotes = undefined;
expectedResult.authors = [];
expectedResult.teams = [];
expectedResult.contactEmails = []; // as there are no referencing teams, there won't be any PMs
expectedResult.workingGroups = [{ title: 'wg', id: '1' }];
expectedResult.publishingEntity = 'Working Group';
expectedResult.researchTheme = [
'PD Functional Genomics',
'Neuro-Immune Interactions',
];

expect(result).toEqual(expectedResult);
});

test('Should return a mix of internal and external authors', async () => {
const researchOutputs = getContentfulResearchOutputGraphqlResponse();
const user1 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ describe('User data provider', () => {
name: 'interest-group-2',
},
{
role: 'Project Manager',
active: true,
id: 'interest-group-leader-1',
name: 'Interest Group Leader 1',
Expand Down Expand Up @@ -383,10 +384,11 @@ describe('User data provider', () => {

test('Should default missing research theme to an empty array', async () => {
const id = 'user-id-1';
const contentfulUser = getContentfulGraphqlUser();
contentfulUser.teamsCollection!.items[0]!.team!.researchTheme = null;

contentfulGraphqlClientMock.request.mockResolvedValueOnce({
users: getContentfulGraphqlUser({
researchTheme: null,
}),
users: contentfulUser,
});

const response = await userDataProvider.fetchById(id);
Expand Down Expand Up @@ -740,6 +742,7 @@ describe('User data provider', () => {
},
{
active: true,
role: 'Project Manager',
id: 'interest-group-leader-1',
name: 'Interest Group Leader 1',
},
Expand Down
3 changes: 3 additions & 0 deletions apps/crn-server/test/fixtures/research-output.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ export const getContentfulResearchOutputGraphqlResponse =
id: 'team-id-0',
},
displayName: 'Team A',
researchTheme: {
name: 'PD Functional Genomics',
},
},
],
},
Expand Down
48 changes: 28 additions & 20 deletions apps/crn-server/test/fixtures/users.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export const getUserResponse = (): UserResponse => ({
{ id: 'cd7be4902', name: 'Brighton' },
{ id: 'cd7be4903', name: 'Liverpool' },
],
researchTheme: ['PD Functional Genomics', 'Neuro-Immune Interactions'],
researchTheme: ['PD Functional Genomics'],
});

export const getUserListItemDataObject = (): UserListItemDataObject => ({
Expand Down Expand Up @@ -225,7 +225,7 @@ export const getPublicUserResponse = (): PublicUserResponse => ({
{ id: 'cd7be4902', name: 'Brighton' },
{ id: 'cd7be4903', name: 'Liverpool' },
],
researchTheme: ['PD Functional Genomics', 'Neuro-Immune Interactions'],
researchTheme: ['PD Functional Genomics'],
researchOutputs: ['research-output-id'],
});

Expand Down Expand Up @@ -321,7 +321,7 @@ export const getUserDataObject = (): UserDataObject => ({
{ id: '4', name: 'expertise 4' },
{ id: '5', name: 'expertise 5' },
],
researchTheme: ['PD Functional Genomics', 'Neuro-Immune Interactions'],
researchTheme: ['PD Functional Genomics'],
researchOutputs: [],
institution: 'some institution',
jobTitle: 'some job title',
Expand Down Expand Up @@ -472,7 +472,6 @@ export const getContentfulGraphqlUser = (
{ sys: { id: '5' }, name: 'expertise 5' },
],
},
researchTheme: ['PD Functional Genomics', 'Neuro-Immune Interactions'],
institution: 'some institution',
jobTitle: 'some job title',
reachOut: 'some reach out',
Expand Down Expand Up @@ -516,6 +515,9 @@ export const getContentfulGraphqlUser = (
linkedFrom: {
interestGroupsCollection: getInterestGroupsCollection(),
},
researchTheme: {
name: 'PD Functional Genomics',
},
proposal: {
sys: {
id: 'proposalId1',
Expand Down Expand Up @@ -669,25 +671,31 @@ const getWorkingGroupCollection = () => ({
],
});

const getInterestGroupLeadersCollection = () => ({
items: [
{
linkedFrom: {
interestGroupsCollection: {
items: [
{
sys: {
id: 'interest-group-leader-1',
type InterestGroupLeadersCollection = NonNullable<
NonNullable<NonNullable<FetchUserByIdQuery>['users']>['linkedFrom']
>['interestGroupLeadersCollection'];

const getInterestGroupLeadersCollection: () => InterestGroupLeadersCollection =
() => ({
items: [
{
role: 'Project Manager',
linkedFrom: {
interestGroupsCollection: {
items: [
{
sys: {
id: 'interest-group-leader-1',
},
active: true,
name: 'Interest Group Leader 1',
},
active: true,
name: 'Interest Group Leader 1',
},
],
],
},
},
},
},
],
});
],
});

export const getUserContentfulWebhookDetail = (
id: string,
Expand Down
Loading

0 comments on commit 043f236

Please sign in to comment.