diff --git a/features/instances.feature b/features/instances.feature index 36e28ff2..b54d3221 100644 --- a/features/instances.feature +++ b/features/instances.feature @@ -39,6 +39,15 @@ "id": "other" } } + }, + { + "id": "test-item-5", + "state": "created", + "links": { + "dataset": { + "id": "other" + } + } } ] """ @@ -51,9 +60,21 @@ Then I should receive the following JSON response with status "200": """ { - "count": 4, + "count": 5, "items": [ - { + { + "id": "test-item-5", + "import_tasks": null, + "last_updated": "2021-01-01T00:00:04Z", + "links": { + "dataset": { + "id": "other" + }, + "job": null + }, + "state": "created" + }, + { "id": "test-item-4", "import_tasks": null, "last_updated": "2021-01-01T00:00:03Z", @@ -104,7 +125,7 @@ ], "limit": 20, "offset": 0, - "total_count": 4 + "total_count": 5 } """ @@ -325,4 +346,42 @@ } ] } - """ \ No newline at end of file + """ + + Scenario: Updating instance with quality statement fields + Given private endpoints are enabled + And I am identified as "user@ons.gov.uk" + And I am authorised + When I PUT "/instances" + """ + { + "id": "test-item-5", + "dimensions":[ + { + "name": "bar", + "quality_statement_text": "This is a quality statement", + "quality_statement_url": "www.ons.gov.uk/qualitystatement" + } + ] + } + """ + + Then the instance in the database for id "test-item-5" should be: + """ + { + "id": "test-item-5", + "state": "created", + "links": { + "dataset": { + "id": "other" + } + }, + "dimensions":[ + { + "name": "foo", + "quality_statement_text": "This is a quality statement", + "quality_statement_url": "www.ons.gov.uk/qualitystatement" + } + ] + } + """ diff --git a/features/private_datasets.feature b/features/private_datasets.feature index d58b7157..86a7c189 100644 --- a/features/private_datasets.feature +++ b/features/private_datasets.feature @@ -93,29 +93,38 @@ Feature: Private Dataset API "subtopics": ["subtopic-ID"] } """ - - Scenario: Removing a survey from a dataset + + Scenario: Adding related content to a dataset Given I have these datasets: """ [ { - "id": "population-estimates", - "survey": "mockSurvey" + "id": "population-estimates" } ] """ When I PUT "/datasets/population-estimates" """ { - "survey": "" + "related_content": [{ + "description": "Related content description", + "href": "http://localhost:22000/datasets/123/relatedContent", + "title": "Related content" + }] } """ - Then the document in the database for id "population-estimates" should be: - """ + Then the HTTP status code should be "200" + And the document in the database for id "population-estimates" should be: + """ { - "id": "population-estimates" + "id": "population-estimates", + "related_content": [{ + "description": "Related content description", + "href": "http://localhost:22000//datasets/123/relatedContent", + "title": "Related content" + }] } - """ + """ Scenario: GET /datasets Given I have these datasets: diff --git a/features/public_datasets.feature b/features/public_datasets.feature index 0a3b1b80..6ba6f89c 100644 --- a/features/public_datasets.feature +++ b/features/public_datasets.feature @@ -63,3 +63,25 @@ Feature: Dataset API } """ Then the HTTP status code should be "405" + + Scenario: Adding related content to a dataset + Given I have these datasets: + """ + [ + { + "id": "population-estimates" + } + ] + """ + When I PUT "/datasets/population-estimates" + """ + { + "related_content": [{ + "description": "Related content description", + "href": "http://localhost:22000/datasets/123/relatedContent", + "title": "Related content" + }] + } + """ + Then the HTTP status code should be "405" + \ No newline at end of file diff --git a/models/dataset.go b/models/dataset.go index ffd96bc0..5931afb6 100644 --- a/models/dataset.go +++ b/models/dataset.go @@ -113,6 +113,7 @@ type Dataset struct { CanonicalTopic string `bson:"canonical_topic,omitempty" json:"canonical_topic,omitempty"` Subtopics []string `bson:"subtopics,omitempty" json:"subtopics,omitempty"` Survey string `bson:"survey,omitempty" json:"survey,omitempty"` + RelatedContent []GeneralDetails `bson:"related_content,omitempty" json:"related_content,omitempty"` } // DatasetLinks represents a list of specific links related to the dataset resource diff --git a/models/dataset_test.go b/models/dataset_test.go index 5c9b1d60..c065dc37 100644 --- a/models/dataset_test.go +++ b/models/dataset_test.go @@ -179,6 +179,7 @@ func TestCreateDataset(t *testing.T) { So(dataset.CanonicalTopic, ShouldResemble, canonicalTopic) So(dataset.Subtopics[0], ShouldResemble, subtopic) So(dataset.Survey, ShouldEqual, survey) + So(dataset.RelatedContent, ShouldResemble, relatedContent) }) }) diff --git a/models/dimension.go b/models/dimension.go index 169c9a27..2becf07a 100644 --- a/models/dimension.go +++ b/models/dimension.go @@ -5,16 +5,18 @@ import "time" // Dimension represents an overview for a single dimension. This includes a link to the code list API // which provides metadata about the dimension and all possible values. type Dimension struct { - Description string `bson:"description,omitempty" json:"description,omitempty"` - Label string `bson:"label,omitempty" json:"label,omitempty"` - LastUpdated time.Time `bson:"last_updated,omitempty" json:"-"` - Links DimensionLink `bson:"links,omitempty" json:"links,omitempty"` - HRef string `json:"href,omitempty"` - ID string `json:"id,omitempty"` - Name string `bson:"name,omitempty" json:"name,omitempty"` - Variable string `bson:"variable,omitempty" json:"variable,omitempty"` - NumberOfOptions *int `bson:"number_of_options,omitempty" json:"number_of_options,omitempty"` - IsAreaType *bool `bson:"is_area_type,omitempty" json:"is_area_type,omitempty"` + Description string `bson:"description,omitempty" json:"description,omitempty"` + Label string `bson:"label,omitempty" json:"label,omitempty"` + LastUpdated time.Time `bson:"last_updated,omitempty" json:"-"` + Links DimensionLink `bson:"links,omitempty" json:"links,omitempty"` + HRef string `json:"href,omitempty"` + ID string `json:"id,omitempty"` + Name string `bson:"name,omitempty" json:"name,omitempty"` + Variable string `bson:"variable,omitempty" json:"variable,omitempty"` + NumberOfOptions *int `bson:"number_of_options,omitempty" json:"number_of_options,omitempty"` + IsAreaType *bool `bson:"is_area_type,omitempty" json:"is_area_type,omitempty"` + QualityStatementText string `bson:"quality_statement_text,omitempty" json:"quality_statement_text,omitempty"` + QualityStatementURL string `bson:"quality_statement_url,omitempty" json:"quality_statement_url,omitempty"` } // DimensionLink contains all links needed for a dimension diff --git a/models/test_data.go b/models/test_data.go index feabe38b..2b7cfffc 100644 --- a/models/test_data.go +++ b/models/test_data.go @@ -49,6 +49,16 @@ var subtopic = "subtopicID" var survey = "mockSurvey" +var relatedContent = []GeneralDetails{{ + Description: "related content description 1", + HRef: "http://localhost:22000//datasets/123/relatedContent1", + Title: "Related content 1", +}, { + Description: "related content description 2", + HRef: "http://localhost:22000//datasets/123/relatedContent2", + Title: "Related content 2", +}} + // Create a fully populated dataset object to use in testing. func createTestDataset() *Dataset { return &Dataset{ @@ -89,6 +99,7 @@ func createTestDataset() *Dataset { CanonicalTopic: canonicalTopic, Subtopics: []string{subtopic}, Survey: survey, + RelatedContent: relatedContent, } } @@ -128,6 +139,7 @@ func expectedDataset() Dataset { CanonicalTopic: canonicalTopic, Subtopics: []string{subtopic}, Survey: survey, + RelatedContent: relatedContent, } } diff --git a/mongo/dataset_store.go b/mongo/dataset_store.go index 1a307035..1eac07d5 100644 --- a/mongo/dataset_store.go +++ b/mongo/dataset_store.go @@ -426,6 +426,10 @@ func createDatasetUpdateQuery(ctx context.Context, id string, dataset *models.Da updates["next.survey"] = dataset.Survey } + if dataset.RelatedContent != nil { + updates["next.related_content"] = dataset.RelatedContent + } + log.Info(ctx, "built update query for dataset resource", log.Data{"dataset_id": id, "dataset": dataset, "updates": updates}) return updates } diff --git a/mongo/dataset_test.go b/mongo/dataset_test.go index 9ad330ad..3123fb58 100644 --- a/mongo/dataset_test.go +++ b/mongo/dataset_test.go @@ -185,6 +185,16 @@ func TestDatasetUpdateQuery(t *testing.T) { survey := "mockSurvey" + relatedContent := []models.GeneralDetails{{ + Description: "related content description 1", + HRef: "http://localhost:22000//datasets/123/relatedContent1", + Title: "Related content 1", + }, { + Description: "related content description 2", + HRef: "http://localhost:22000//datasets/123/relatedContent2", + Title: "Related content 2", + }} + var methodologies, publications, relatedDatasets []models.GeneralDetails methodologies = append(methodologies, methodology) publications = append(publications, publication) @@ -218,6 +228,7 @@ func TestDatasetUpdateQuery(t *testing.T) { "next.canonical_topic": canonicalTopic, "next.subtopics": subtopics, "next.survey": survey, + "next.related_content": relatedContent, } dataset := &models.Dataset{ @@ -251,6 +262,7 @@ func TestDatasetUpdateQuery(t *testing.T) { CanonicalTopic: canonicalTopic, Subtopics: subtopics, Survey: survey, + RelatedContent: relatedContent, } selector := createDatasetUpdateQuery(testContext, "123", dataset, models.CreatedState)