Skip to content

Commit

Permalink
Merge branch 'feature/1183-support-census-branding' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Fleming committed Oct 20, 2022
2 parents 571f330 + f705a33 commit b8ed192
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 92 deletions.
2 changes: 1 addition & 1 deletion Dockerfile-local
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.17-stretch as build
FROM golang:1.18-stretch as build

RUN apt-get update && apt-get upgrade -y

Expand Down
4 changes: 2 additions & 2 deletions Dockerfile.local
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM golang:1.17-stretch AS base
FROM golang:1.18-stretch AS base

ENV GOCACHE=/go/.go/cache GOPATH=/go/.go/path TZ=Europe/London

RUN GOBIN=/bin go get github.com/cespare/reflex
RUN GOBIN=/bin go install github.com/cespare/reflex@latest

# Map between the working directories of dev and live
RUN ln -s /go /dp-dataset-api
Expand Down
99 changes: 58 additions & 41 deletions features/private_datasets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Feature: Private Dataset API
forbidden - dataset already exists
"""

Scenario: Adding canonical and subtopic fields to a dataset
Scenario: Adding survey field to a dataset
Given I have these datasets:
"""
[
Expand All @@ -56,32 +56,67 @@ Feature: Private Dataset API
When I PUT "/datasets/population-estimates"
"""
{
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"survey": "mockSurvey"
}
"""
Then the HTTP status code should be "200"
And the document in the database for id "population-estimates" should be:
"""
{
"id": "population-estimates",
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"survey": "mockSurvey"
}
"""

Scenario: Adding topic fields to a dataset
Given I have these datasets:
"""
[
{
"id": "population-estimates"
}
]
"""
When I PUT "/datasets/population-estimates"
"""
{
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"]
}
"""
Then the HTTP status code should be "200"
And the document in the database for id "population-estimates" should be:
"""
{
"id": "population-estimates",
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"]
}
"""

Scenario: Removing a survey from a dataset
Given I have these datasets:
"""
[
{
"id": "population-estimates",
"survey": "mockSurvey"
}
]
"""
When I PUT "/datasets/population-estimates"
"""
{
"survey": ""
}
"""
Then the document in the database for id "population-estimates" should be:
"""
{
"id": "population-estimates"
}
"""

Scenario: GET /datasets
Given I have these datasets:
"""
Expand Down Expand Up @@ -119,14 +154,8 @@ Feature: Private Dataset API
[
{
"id": "population-estimates",
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"]
}
]
"""
Expand All @@ -139,25 +168,13 @@ Feature: Private Dataset API
"id": "population-estimates",
"next": {
"id": "population-estimates",
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"]
},
"current": {
"id": "population-estimates",
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"]
}
}],
"limit": 20,
Expand Down
13 changes: 4 additions & 9 deletions features/public_datasets.feature
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Feature: Dataset API
}
"""

Scenario: Adding canonical and subtopic fields to a dataset
Scenario: Adding topic and survey fields to a dataset
Given I have these datasets:
"""
[
Expand All @@ -57,14 +57,9 @@ Feature: Dataset API
When I PUT "/datasets/population-estimates"
"""
{
"canonical_topic": {
"id": "canonical-topic-ID",
"title": "Canonical topic title"
},
"sub_topics": [{
"id": "subtopic-ID",
"title": "Subtopic title"
}]
"canonical_topic": "canonical-topic-ID",
"subtopics": ["subtopic-ID"],
"survey": "mockSurvey"
}
"""
Then the HTTP status code should be "405"
10 changes: 3 additions & 7 deletions models/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,9 @@ type Dataset struct {
Type string `bson:"type,omitempty" json:"type,omitempty"`
NomisReferenceURL string `bson:"nomis_reference_url,omitempty" json:"nomis_reference_url,omitempty"`
IsBasedOn *IsBasedOn `bson:"is_based_on,omitempty" json:"is_based_on,omitempty"`
CanonicalTopic *Topic `bson:"canonical_topic,omitempty" json:"canonical_topic,omitempty"`
SubTopics []Topic `bson:"sub_topics,omitempty" json:"sub_topics,omitempty"`
}

type Topic struct {
ID string `bson:"id,omitempty" json:"id,omitempty"`
Title string `bson:"title,omitempty" json:"title,omitempty"`
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"`
}

// DatasetLinks represents a list of specific links related to the dataset resource
Expand Down
5 changes: 3 additions & 2 deletions models/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,9 @@ func TestCreateDataset(t *testing.T) {
So(dataset.URI, ShouldEqual, "http://localhost:22000/datasets/123/breadcrumbs")
So(dataset.Type, ShouldEqual, "filterable")
So(dataset.NomisReferenceURL, ShouldEqual, "")
So(dataset.CanonicalTopic, ShouldResemble, &canonicalTopic)
So(dataset.SubTopics[0], ShouldResemble, subtopic)
So(dataset.CanonicalTopic, ShouldResemble, canonicalTopic)
So(dataset.Subtopics[0], ShouldResemble, subtopic)
So(dataset.Survey, ShouldEqual, survey)
})
})

Expand Down
22 changes: 10 additions & 12 deletions models/test_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,11 @@ var relatedDatasets = GeneralDetails{
Title: "Census Age",
}

var canonicalTopic = Topic{
ID: "canonicalTopicID",
Title: "Canonical topic title",
}
var canonicalTopic = "canonicalTopicID"

var subtopic = Topic{
ID: "subtopicID",
Title: "Subtopic title",
}
var subtopic = "subtopicID"

var survey = "mockSurvey"

// Create a fully populated dataset object to use in testing.
func createTestDataset() *Dataset {
Expand Down Expand Up @@ -90,8 +86,9 @@ func createTestDataset() *Dataset {
URI: "http://localhost:22000/datasets/123/breadcrumbs",
Type: "filterable",
NomisReferenceURL: "",
CanonicalTopic: &canonicalTopic,
SubTopics: []Topic{subtopic},
CanonicalTopic: canonicalTopic,
Subtopics: []string{subtopic},
Survey: survey,
}
}

Expand Down Expand Up @@ -128,8 +125,9 @@ func expectedDataset() Dataset {
URI: "http://localhost:22000/datasets/123/breadcrumbs",
Type: "filterable",
NomisReferenceURL: "",
CanonicalTopic: &canonicalTopic,
SubTopics: []Topic{subtopic},
CanonicalTopic: canonicalTopic,
Subtopics: []string{subtopic},
Survey: survey,
}
}

Expand Down
10 changes: 7 additions & 3 deletions mongo/dataset_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,16 @@ func createDatasetUpdateQuery(ctx context.Context, id string, dataset *models.Da
updates["next.nomis_reference_url"] = dataset.NomisReferenceURL
}

if dataset.CanonicalTopic != nil {
if dataset.CanonicalTopic != "" {
updates["next.canonical_topic"] = dataset.CanonicalTopic
}

if dataset.SubTopics != nil {
updates["next.sub_topics"] = dataset.SubTopics
if len(dataset.Subtopics) > 0 {
updates["next.subtopics"] = dataset.Subtopics
}

if dataset.Survey != "" {
updates["next.survey"] = dataset.Survey
}

log.Info(ctx, "built update query for dataset resource", log.Data{"dataset_id": id, "dataset": dataset, "updates": updates})
Expand Down
25 changes: 10 additions & 15 deletions mongo/dataset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,11 @@ func TestDatasetUpdateQuery(t *testing.T) {
Title: "some dataset title",
}

canonicalTopic := models.Topic{
ID: "canonicalTopicID",
Title: "Canonical topic title",
}
canonicalTopic := "canonicalTopicID"

subtopics := []string{"secondaryTopic1ID", "secondaryTopic2ID"}

subTopics := []models.Topic{{
ID: "secondaryTopic1ID",
Title: "Secondary topic 1 title",
}, {
ID: "secondaryTopic2ID",
Title: "Secondary topic 2 title",
}}
survey := "mockSurvey"

var methodologies, publications, relatedDatasets []models.GeneralDetails
methodologies = append(methodologies, methodology)
Expand Down Expand Up @@ -222,8 +215,9 @@ func TestDatasetUpdateQuery(t *testing.T) {
"next.uri": "http://ons.gov.uk/datasets/123/landing-page",
"next.type": "nomis",
"next.nomis_reference_url": "https://www.nomisweb.co.uk/census/2011/ks106ew",
"next.canonical_topic": &canonicalTopic,
"next.sub_topics": subTopics,
"next.canonical_topic": canonicalTopic,
"next.subtopics": subtopics,
"next.survey": survey,
}

dataset := &models.Dataset{
Expand Down Expand Up @@ -254,8 +248,9 @@ func TestDatasetUpdateQuery(t *testing.T) {
URI: "http://ons.gov.uk/datasets/123/landing-page",
Type: "nomis",
NomisReferenceURL: "https://www.nomisweb.co.uk/census/2011/ks106ew",
CanonicalTopic: &canonicalTopic,
SubTopics: subTopics,
CanonicalTopic: canonicalTopic,
Subtopics: subtopics,
Survey: survey,
}

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

0 comments on commit b8ed192

Please sign in to comment.