Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

toContainIDs #51

Open
M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Open

toContainIDs #51

M-Scott-Lassiter opened this issue Jun 8, 2022 · 0 comments
Assignees
Labels
new matcher proposal Proposal for a new GeoJSON matcher

Comments

@M-Scott-Lassiter
Copy link
Owner

Description

GeoJSON Features have an optional ID member that can be any string or number. This matcher verifies that all Features within a FeatureCollection contain valid IDs.

If a Feature has a commonly used identifier, that identifier SHOULD be included as a member of the Feature object with the name "id", and the value of this member is either a JSON string or number.

~ https://datatracker.ietf.org/doc/html/rfc7946#section-3.2

An "id" member on a non-feature object gets treated as a foreign member instead of an ID. Therefore, this matcher rejects non-FeatureCollection objects.

This test will fail if any of the features do not have an ID, or if the "features" member is an empty array.

Example Matcher Usage

const goodTtestCollection1 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 1
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 3
    }]
}
const goodTtestCollection2 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: "Test 1"
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }]
}
const badTestCollection1 = {
    type: "FeatureCollection",
    features: []
}
const badTestCollection2 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 11
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
    }]
}

expect(goodTtestCollection1).toContainNumericIDs()
expect(goodTtestCollection2).toContainNumericIDs()

expect(badTestCollection1).not.toContainNumericIDs()
expect(badTestCollection2).not.toContainNumericIDs()
expect(goodTtestCollection1.features[0]).not.toContainNumericIDs()

Passing Tests

Unique IDs

For both Strings, Numbers, and Combinations:

  • FeatureCollection with Single Feature with ID
  • FeatureCollection with 5 Features and unique IDs
  • Stress Test: FeatureCollection with 100 Features and unique IDs

Identical IDs

For both Strings, Numbers, and Combinations:

  • FeatureCollection with 5 Features and some repeated IDs
  • FeatureCollection with 5 Features and all repeated IDs

Failing Tests

Invalid Inputs To Matcher

Rejects each of the following:

  • Each of the seven Geometry objects
  • FeatureCollection object
  • undefined, null, false, true, 0
  • { someProp: 'I am not GeoJSON', id: 4 }
  • '',
  • 'Random Feature',
  • JSON.stringify({
          type: 'FeatureCollection',
          features: []
      })

Only Some Have IDs, the Rest Null or Not Mentioned

For both Strings, Numbers, and Combinations:

  • FeatureCollection with 5 Features, 1 has no "id" member
  • FeatureCollection with 5 Features, 1 has an "id" member with null

FeatureCollection with Empty Features Array

Should fail because there are no features to check IDs on.

FeatureCollection with No ID

  • Should fail with a single feature that has no ID.
  • Should fail with a single feature that has ID of null.
@M-Scott-Lassiter M-Scott-Lassiter added the new matcher proposal Proposal for a new GeoJSON matcher label Jun 8, 2022
@M-Scott-Lassiter M-Scott-Lassiter added this to To do in Feature Collections via automation Jun 8, 2022
@M-Scott-Lassiter M-Scott-Lassiter self-assigned this Jun 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new matcher proposal Proposal for a new GeoJSON matcher
Projects
Development

No branches or pull requests

1 participant