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

toHaveID #36

Closed
M-Scott-Lassiter opened this issue Jun 5, 2022 · 1 comment
Closed

toHaveID #36

M-Scott-Lassiter opened this issue Jun 5, 2022 · 1 comment

Comments

@M-Scott-Lassiter
Copy link
Owner

M-Scott-Lassiter commented Jun 5, 2022

Description

GeoJSON Features have an optional ID member that can be any string or number.

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.

This matcher will take an optional argument of either a string, number, RegExp, or array of any combination of these. If no argument is provided, the matcher will check if the Feature object has an ID member of any value. Otherwise, it will check that the ID member exactly matches either the single input or any of the array values.

Valid GeoJSON Examples

{
    "type": "Feature",
    "id": "f1",
    "geometry": {...},
    "properties": {...}
}
Example Matcher Usage
const testFeature = {
    type: 'Feature',
    id: 'f1',
    geometry: {...},
    properties: {...}
}

expect(testFeature).toHaveID()
expect(testFeature).toHaveID('f1')
expect(testFeature).toHaveID([ 1, 'F', 'F12', /[a-z]+[0-9]+/])

expect(testFeature).not.toHaveID(123)

Passing Tests

Numeric or String ID

Input:

  • 0

  • -200

  • 200

  • Infinity

  • -Infinity

  • '1'

  • 'Test 123'

  • 'Random ID String'

  • Empty string: ''

  • const testFeature = {
      type: 'Feature',
      id: <input>,
      geometry: null,
      properties: null
    }
    
  • Using the matcher without an optional argument

  • Using the matcher with the input argument

  • Using the matcher with the input argument as a single element array

  • Using the matcher with the input argument as a RegExp

  • Using the matcher with the input argument as a single element array as a RegExp

Empty Array for Optional Argument

Input: 'Test ID', 3

const testFeature = {
    type: 'Feature',
    id: 'Test ID',
    geometry: null,
    properties: null
}

expect(feature).toHaveStringID([])

Multiple Array Value Checking for Numeric ID

Only one element passes:

  • [1, 2, 3, 719]
  • ['1', 719, '2', '3']
  • [/[0-9]+/, 2, 3, 'F1']
  • [755, /71[0-9]/]

More than one element passes:

  • [/72[0-9]/, /81[0-9]/, /71[0-9]/, /[0-9]+/]
const testFeature = {
    type: 'Feature',
    id: 719,
    geometry: null,
    properties: null
}

Multiple Array Value Checking for String ID

const testFeature = {
    type: 'Feature',
    id: 'Some String',
    geometry: null,
    properties: null
}

Only one element passes:

  • ['1', 719, '2', 3, 'Some String']
  • ['A String ID', /Some/, 2]
  • [/SomeString/, /123/, /\bString\b/]

More than one element passes:

  • [/72[0-9]/, /\bString\b/, /71[0-9]/, /Some/]

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: 'Feature',
        geometry: null,
        properties: null
    })

Valid Feature Does Not Have ID

const testFeature = {
    type: 'Feature',
    geometry: null,
    properties: null
}

Invalid Feature Provided

Invalid features should throw the toBeFeature errors instead of new ones here.

Invalid Inputs To Optional Argument

Rejects when the optional ID to check is

  • Each of the seven Geometry objects
  • Feature or FeatureCollection object
  • undefined, null, false, true
  • { someProp: 'I am not GeoJSON', id: 4 }
  • an empty object: {}
  • NaN

Rejects when ID Does Not Match Optional Input Value

  • String ID that does not match
  • Array of String IDs that do not match
  • Number ID that does not match
  • Array of Number IDs that do not match
  • RegExp that does not match
  • Array of RegExp that does not match
@M-Scott-Lassiter M-Scott-Lassiter added the new matcher proposal Proposal for a new GeoJSON matcher label Jun 5, 2022
@M-Scott-Lassiter M-Scott-Lassiter added this to To do in Features via automation Jun 5, 2022
@M-Scott-Lassiter M-Scott-Lassiter self-assigned this Jun 5, 2022
This was referenced Jun 7, 2022
@M-Scott-Lassiter M-Scott-Lassiter moved this from To do to In progress in Features Jun 7, 2022
@M-Scott-Lassiter M-Scott-Lassiter mentioned this issue Jun 7, 2022
19 tasks
Features automation moved this from In progress to Done Jun 7, 2022
@M-Scott-Lassiter M-Scott-Lassiter added matchers/features and removed new matcher proposal Proposal for a new GeoJSON matcher labels Jun 7, 2022
github-actions bot pushed a commit that referenced this issue Jun 7, 2022
## [1.2.0](v1.1.0...v1.2.0) (2022-06-07)

### 🎁 Feature Changes

* **toHaveID:** add new matcher ([5bae7f0](5bae7f0)), closes [#36](#36)

### 🧭 API Documentation Changes

* **toHaveID:** fix documentation typo. ([c0f731b](c0f731b))
@M-Scott-Lassiter
Copy link
Owner Author

🎉 This issue has been resolved in version 1.2.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Features
  
Done
Development

No branches or pull requests

1 participant