Skip to content

Review component test for PUT instances #414

Description

@rafahop

The component test step the instance in the database for id "id" should be: is not returning an error when the assertion fails:

func (c *DatasetComponent) theInstanceInTheDatabaseForIdShouldBe(id string, body *godog.DocString) error {
var expected models.Instance
if err := json.Unmarshal([]byte(body.Content), &expected); err != nil {
return fmt.Errorf("failed to unmarshal body: %w", err)
}
collectionName := c.MongoClient.ActualCollectionName(config.InstanceCollection)
var got models.Instance
if err := c.MongoClient.Connection.Collection(collectionName).FindOne(context.Background(), bson.M{"_id": id}, &got); err != nil {
return fmt.Errorf("failed to get instance from collection: %w", err)
}
assert.Equal(&c.ErrorFeature, expected, got)
return nil
}

And therefore the component tests using this step are wrongly passing.

The function should return c.ErrorFeature.StepError() so that the test fails when there are discrepancies in the expected value.

However, the component tests will need to be reviewed and rewritten as they won't pass as they are.
Also, they seem to be calling an endpoint that does not even exist:

When I PUT "/instances"
"""
{
"id": "test-item-4",
"dimensions":[
{
"name": "foo",
"is_area_type": false,
}
]
}
"""

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"
}
]
}
"""

Presumably they should be calling PUT "/instances/{instance_id}"

A review of these tests is required

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions