-
Notifications
You must be signed in to change notification settings - Fork 0
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
#2 push method #8
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if there is a such thing as too many comments... naaaahhh
I didn't review the jest tests, is that bad?
Co-Authored-By: Chris Petty <[email protected]>
Co-Authored-By: Chris Petty <[email protected]>
Co-Authored-By: Chris Petty <[email protected]>
I wouldn't mind more thoughts on the comments if you had time - did they help you, with little understanding of much else, understand the code easily? Or were they just annoying? (I like comments for functions which are obscure/dependent on strange inputs), still trying to find a balance! Also it's fine with the tests - I was going to add more but didn't want to make the PR too big, prob make an issue for more - i.e. with malformed input etc, rather than just status codes |
Just a note in case I forget. The API has changed and now returns |
I'm not 100% up to speed, but maybe 422 would be accurate? This is largely internal right? So long as it's well documented it's probably not a big bother if it's not the absolute best option (if figuring that out takes excessive amounts of time) https://www.bennadel.com/blog/2434-http-status-codes-for-invalid-data-400-vs-422.htm |
I didn't actually know about 422, that would def be ideal. The 400 response is what is sent from the API, which I don't have any control over (they're probably sick of our suggestions already), so it will just send a 400. |
Added some tests for the utlity method and request method.. sorry :( |
invalidObjects.push(invalidDatum); | ||
}); | ||
return { data: originalDataClone, invalidData: invalidObjects }; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please provide possible erroneous response in a comment below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess i can look it up in testData/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% what you want here, you mean responses from the API that are errors? Maybe best for the wiki? I haven't added any to the test cases as that case essentially is testing the helper method (Also hard to mock default import of axios
twice in one test). Hard to find a balance for number of tests written - I think trying to go for 100% coverage is a bit of a trap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just needed an example of erroneous response, but found/figured it out
src/utilities/requestUtilities.js
Outdated
// is an error message. | ||
const { row } = errorObject; | ||
// If the row value is valid, remove the index from the original data | ||
if (!Number.isInteger(Number(row)) || row >= invalidData.length) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
originalData.length ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if so, maybe should add index out of bound to removeInvalidObjectsTestData test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
49509f4 have added a check here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i mean instead of row >= invalidData.length, should be row >= originalData.length ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const { row } = errorObject; | ||
// If the row value is valid, remove the index from the original data | ||
if (!Number.isInteger(Number(row)) || row >= invalidData.length) return; | ||
const [invalidDatum] = originalDataClone.splice(row, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try this method with removeInvalidObjectsTestData like this:
TEST_FIVE: {
INPUT: { originalData: [1, 2, 3], invalidData: { errors: [{ row: 0 }, { row: 2 }] } },
OUTPUT: { data: [2], invalidData: [1,3] },
},
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
0ba216b I added a couple more test cases - one for the above comment and also this case (Although I'm not 100% sure what it was going for?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
does that test run fine ? i think it would fail, once you splice a row from originalDataClone, it becomes length of 2 ? then try to splice an index that doesn't exist (2)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah yeah it does run fine - it first sorts the invalid data by row in descending order. So we would splice 2 first, then 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice
src/requests/surveyResponse.js
Outdated
// which lists the indicies which are invalid with a status code of | ||
// 200. | ||
const { data: response } = await Axios(apiConfig); | ||
const { errors } = response; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we check for presence of "error" (just in case API response has unknown error with still 200 reponse)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8a4efa9 added this here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@joshxg, looks good to me, merge at will
Lol this PR doubled since my last review. Most tested utility method eva |
* 7 : calling with an empty, but existing, errors array | ||
* 8 : calling with an error index being out of range | ||
*/ | ||
test('Should pass all tests', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In terms of Jest output, isn't this just going to show:
❎ Should pass all tests
i.e. no context
Ages ago I went through the Jasmine docs as I think it has a nice way of presenting making a test suite (JEST basically took the same API): https://jasmine.github.io/tutorials/your_first_suite
Or more specifically just the docs for describe in Jest here: https://jestjs.io/docs/en/api#describename-fn
In that case it'd be
describe('removeInvalidObjects', () => {
test('removes all data, as all have errors', () => {
const result = removeInvalidObjects([1, 2, 3], { errors: [{ row: 0 }, { row: 1 }, { row: 2 }] })
expect(result).toEqual([3, 2, 1])
}
test('removing one object, as only one has an error', () => {
...
}
...
}
That'd make the test output a bit more useful/typical I'd presume. Also not sure what affect your forEach might have on Jest's multithread support. Ew I just went in a not so relevant rabbit hole jestjs/jest#6694
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting rabbit hole! (I hope this doesn't get to 7,000 tests :( )
Regarding the tests though: You're right on the description, it will just show no real context. I have been wanting to look more into testing and making suites, I've just been doing it very un-researched currently.
As for the forEach
, I didn't look into any implications, it just seemed like a nice easy way to run, add, modify tests. Definitely given me lots to look into though!
Fixes #2
Main addition:
surveyResponse
method which will push data to the Tupaia serverMinor additions: