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

toContainUniqueIDs #52

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

toContainUniqueIDs #52

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 that are all unique.

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 matcher takes an optional boolean argument, allowNulls. It will default to false. If set to true, the matcher ignores features that do not have an "id" member, or have the value of "id" explicitly set to null.

This test will fail if any of the features repeat a repeated ID, or if the "features" member is an empty array.

Example Matcher Usage

const testCollection1 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 1
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 3
    }]
}
const testCollection2 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: "Test 1"
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 2
    }]
}
const testCollection3 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 700
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 700
    }]
}
const testCollection4 = {
    type: "FeatureCollection",
    features: [{
        type: "Feature",
        geometry: {...},
        properties: {...},
        id: 711
    }, {
        type: "Feature",
        geometry: {...},
        properties: {...},
    }]
}

expect(testCollection1).toContainUniqueIDs()
expect(testCollection2).toContainUniqueIDs()
expect(testCollection4).toContainUniqueIDs(true)

expect(badTestCollection1).not.toContainUniqueIDs()
expect(badTestCollection2).not.toContainUniqueIDs()
expect(badTestCollection3).not.toContainUniqueIDs()
expect(badTestCollection4).not.toContainUniqueIDs()
expect(badTestCollection4).not.toContainUniqueIDs(false)

Passing Tests

Unique IDs

For both Strings, Numbers, and Combinations:

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

Only Some Have IDs, the Rest Null or Not Mentioned, allowNulls is True

For both Strings, Numbers, and Combinations:

  • FeatureCollection with Multiple Features, 1 has no "id" member
  • FeatureCollection with Multiple Features, 1 has an "id" member with null
  • FeatureCollection with Multiple Features, several have no "id" member
  • FeatureCollection with Multiple Features, several have an "id" member with null

FeatureCollection with No ID, allowNulls is True

  • Single feature that has no ID.
  • Single feature that has ID of null.
  • Multiple features that has no ID.
  • Multiple features that has ID of null.

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: []
      })

Identical IDs

For both Strings, Numbers, and Combinations:

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

Only Some Have IDs, the Rest Null or Not Mentioned, allowNulls is False

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, allowNulls is False

  • Single feature that has no ID.
  • Single feature that has ID of null.
  • Multiple features that has no ID.
  • Multiple features 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