wayfair-incubator / gqmock

Project generated via @wayfair-incubator oss-template
MIT License
6 stars 2 forks source link

fix: handle null args #31

Closed finn-orsini closed 1 year ago

finn-orsini commented 1 year ago

Description

When using this package to mock relay pagination spec, ran into the following failures:

[gql:mocks] /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:98
[gql:mocks]         return Object.entries(args).reduce((acc, [, value]) => {
[gql:mocks]                       ^
[gql:mocks] 
[gql:mocks] TypeError: Cannot convert undefined or null to object
[gql:mocks]     at Function.entries (<anonymous>)
[gql:mocks]     at SeedManager.argumentCount (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:98:23)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:100:35
[gql:mocks]     at Array.reduce (<anonymous>)
[gql:mocks]     at SeedManager.argumentCount (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:98:37)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:120:43
[gql:mocks]     at Array.findIndex (<anonymous>)
[gql:mocks]     at SeedManager.findSeed (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:115:69)
[gql:mocks]     at SeedManager.mergeOperationResponse (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:137:42)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/routes/graphql.js:74:69
[gql:mocks] /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:87
[gql:mocks]         const argsMatch = Object.entries(source).every(([argumentName, argumentValue]) => {
[gql:mocks]                                  ^
[gql:mocks] 
[gql:mocks] TypeError: Cannot convert undefined or null to object
[gql:mocks]     at Function.entries (<anonymous>)
[gql:mocks]     at SeedManager.matchArguments (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:87:34)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:90:29
[gql:mocks]     at Array.every (<anonymous>)
[gql:mocks]     at SeedManager.matchArguments (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:87:50)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:116:36
[gql:mocks]     at Array.findIndex (<anonymous>)
[gql:mocks]     at SeedManager.findSeed (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:115:69)
[gql:mocks]     at SeedManager.mergeOperationResponse (/Users/sorsini/code/os/gqmock/dist/seed/SeedManager.js:137:42)
[gql:mocks]     at /Users/sorsini/code/os/gqmock/dist/routes/graphql.js:74:69

due to some of the arguments being intentionally null (for example, the cursor on a refetch.

Tested fix on several different mocks including the above nulls!

Type of Change

Checklist

codecov[bot] commented 1 year ago

Codecov Report

Merging #31 (b4c0552) into main (8cac819) will not change coverage. The diff coverage is 100.00%.

@@           Coverage Diff           @@
##             main      #31   +/-   ##
=======================================
  Coverage   94.44%   94.44%           
=======================================
  Files          13       13           
  Lines         486      486           
  Branches      147      147           
=======================================
  Hits          459      459           
  Misses         27       27           
Files Changed Coverage Δ
src/seed/SeedManager.ts 100.00% <100.00%> (ø)