Skip to content

Commit

Permalink
Merge branch 'release/1.49.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
s-xton committed Oct 27, 2022
2 parents a3ce5a3 + 812a0f5 commit de6992a
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 23 deletions.
67 changes: 63 additions & 4 deletions features/instances.feature
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@
"id": "other"
}
}
},
{
"id": "test-item-5",
"state": "created",
"links": {
"dataset": {
"id": "other"
}
}
}
]
"""
Expand All @@ -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",
Expand Down Expand Up @@ -104,7 +125,7 @@
],
"limit": 20,
"offset": 0,
"total_count": 4
"total_count": 5
}
"""

Expand Down Expand Up @@ -325,4 +346,42 @@
}
]
}
"""
"""

Scenario: Updating instance with quality statement fields
Given private endpoints are enabled
And I am identified as "[email protected]"
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"
}
]
}
"""
27 changes: 18 additions & 9 deletions features/private_datasets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions features/public_datasets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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"

1 change: 1 addition & 0 deletions models/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions models/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down
22 changes: 12 additions & 10 deletions models/dimension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions models/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -89,6 +99,7 @@ func createTestDataset() *Dataset {
CanonicalTopic: canonicalTopic,
Subtopics: []string{subtopic},
Survey: survey,
RelatedContent: relatedContent,
}
}

Expand Down Expand Up @@ -128,6 +139,7 @@ func expectedDataset() Dataset {
CanonicalTopic: canonicalTopic,
Subtopics: []string{subtopic},
Survey: survey,
RelatedContent: relatedContent,
}
}

Expand Down
4 changes: 4 additions & 0 deletions mongo/dataset_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
12 changes: 12 additions & 0 deletions mongo/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -251,6 +262,7 @@ func TestDatasetUpdateQuery(t *testing.T) {
CanonicalTopic: canonicalTopic,
Subtopics: subtopics,
Survey: survey,
RelatedContent: relatedContent,
}

selector := createDatasetUpdateQuery(testContext, "123", dataset, models.CreatedState)
Expand Down

0 comments on commit de6992a

Please sign in to comment.