Skip to content

Commit

Permalink
Merge pull request #3086 from ONSdigital/fix-for-supplementary-data-s…
Browse files Browse the repository at this point in the history
…urvey-lists

fix for survey list
  • Loading branch information
martyncolmer authored Dec 11, 2023
2 parents 63bc36f + dfd45ee commit 200fd2e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 18 deletions.
9 changes: 6 additions & 3 deletions eq-author-api/schema/resolvers/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,9 +339,12 @@ const Resolvers = {
`unable to get survey list. status(${response.status})`
);
}
return {
surveyIdList: response.data,
};
return response.data.map((survey) => {
return {
surveyId: survey.survey_id,
surveyName: survey.survey_name,
};
});
} catch (err) {
logger.error(err.message);
return {
Expand Down
17 changes: 12 additions & 5 deletions eq-author-api/schema/tests/SupplementaryDataSurveyIdList.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,31 @@ const fetch = require("node-fetch");
const query = `
query GetSupplementaryDataSurveyIdList {
supplementaryDataSurveyIdList {
surveyIdList
surveyId
surveyName
}
}`;

fetch.mockImplementation(() =>
Promise.resolve({
status: 200,
json: () => ["121", "122", "123"],
json: () => [
{ survey_id: "121", survey_name: "survey1" },
{ survey_id: "122", survey_name: "survey2" },
{ survey_id: "123", survey_name: "survey3" },
],
})
);

describe("SupplementaryDataSurveyIdList", () => {
it("should query supplementary data survey id list schema", async () => {
const expectedResponse = {
data: {
supplementaryDataSurveyIdList: {
surveyIdList: ["121", "122", "123"],
},
supplementaryDataSurveyIdList: [
{ surveyId: "121", surveyName: "survey1" },
{ surveyId: "122", surveyName: "survey2" },
{ surveyId: "123", surveyName: "survey3" },
],
},
};

Expand Down
5 changes: 3 additions & 2 deletions eq-author-api/schema/typeDefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ type SupplementaryDataVersions {
}
type SupplementaryDataSurveyIdList {
surveyIdList: [String]!
surveyId: String!
surveyName: String
}
type SupplementaryDataField {
Expand Down Expand Up @@ -912,7 +913,7 @@ type Query {
collectionLists: CollectionLists
list(input: QueryInput!): List
supplementaryDataVersions(id: ID!): SupplementaryDataVersions
supplementaryDataSurveyIdList: SupplementaryDataSurveyIdList
supplementaryDataSurveyIdList: [SupplementaryDataSurveyIdList]
supplementaryData: SupplementaryData
publishHistory: [PublishHistoryEvent]
listNames: [ListName]
Expand Down
11 changes: 7 additions & 4 deletions eq-author/src/App/dataSettings/SupplementaryDataPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ const SupplementaryDataPage = () => {
const schemaData = tableData?.data;

const surveyIdList =
supplementaryDataSurveyIdList?.supplementaryDataSurveyIdList?.surveyIdList;
supplementaryDataSurveyIdList?.supplementaryDataSurveyIdList;

const handleUnlinkClick = () => {
setShowUnlinkModal(true);
Expand Down Expand Up @@ -244,9 +244,12 @@ const SupplementaryDataPage = () => {
>
Survey ID
</Option>
{surveyIdList?.map((surveyID) => (
<Option key={surveyID} value={surveyID}>
{surveyID}
{surveyIdList?.map((survey) => (
<Option
key={survey.surveyId}
value={survey.surveyId}
>
{survey.surveyId} - {survey.surveyName}
</Option>
))}
</CustomSelect>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ describe("Supplementary dataset page", () => {
} else if (key === GET_SUPPLEMENTARY_DATA_SURVEY_ID_LIST) {
return {
data: {
supplementaryDataSurveyIdList: {
surveyIdList: ["121", "122"],
},
supplementaryDataSurveyIdList: [
{ surveyId: "121", surveyName: "survey1" },
{ surveyId: "122", surveyName: "survey2" },
],
},
};
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
query GetSupplementaryDataSurveyIdList {
supplementaryDataSurveyIdList {
surveyIdList
surveyId
surveyName
}
}

0 comments on commit 200fd2e

Please sign in to comment.