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

Dev/jet/mapd 645/rulecrud spec #650

Merged

Conversation

realtyjustin
Copy link
Contributor

No description provided.

2) simplified handlers for assessing operator calls (via sinon api)
3) simplified assessment of flow through '.then' query callback evaluators, no matter
how many are chained, and easily test input/output of callbacks

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hope you guys don't mind my usage of class docstring-style documentation on this one, per polarmobile/coffeescript-style-guide#39

@realtyjustin
Copy link
Contributor Author

@nmccready @jessecstewart @zacronos @tallented

Looks like it's relatively easy for inadvertent data changes from sql inside specs. I know usually we would just test .toString() on the queries, but it would be nice to have a more solid safeguard just in case. Made a class to help facilitate that, and allow me to improve coverage on the service calls since they do some add'l processing, contain nested calls, etc; things that set it apart from regular crud class operators.

In a nut shell, it just facades in sinon api among the chainable knex operators, nothin really too fancy, but super helpful and makes detailed testing on queries, callbacks, etc really easy.

expectedQuery = """insert into \"config_data_normalization\" (\"config\", \"data_source_id\", \"data_source_type\", \"data_type\", \"input\", \"list\",""" +
""" \"ordering\", \"output\", \"required\") values ('{\\\"DataType\\\":\\\"Int\\\",\\\"nullZero\\\":true}', 'CoreLogic', 'county', 'tax', '\\\"\\\"',""" +
""" 'general', '0', 'Int Param', 'false'), ('{\\\"DataType\\\":\\\"Int\\\",\\\"nullZero\\\":true}', 'CoreLogic', 'county', 'tax', '\\\"\\\"', 'general',""" +
""" '1', 'Another Int Param', 'false')"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The double-quotes in the string don't need to be escaped when using """ as the outer delimiter. (It would be much more readable without the extra escapes.)

As a side note since you brought it up Justin, one consequence of code like this (testing the generated query string) is that our test is fragile -- it relies on how knex handles things internally. If knex makes a change and the order of the columns changes, for example, both knex and our code would still be doing things correctly, but this test would fail. That doesn't mean we have to stop doing it, but it does mean that ideally we could find a better way to handle things that is less fragile.

Also, knex currently has a bug causing it to put extra escapes in when generating a query string (but not when executing the query for real). So this test will break if knex fixes that bug. knex/knex#1021

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok let me try to revisit that then... I had a heck of a time with that for a while last night though, it wanted more escape in the values section.

I agree about the query string testing... classic nondeterministic element ordering and compiling. I think until now it's just been the lowest hanging fruit for us, so it's currently used often, and I'm just being consistent. Hopefully, some of the offerings of that SqlMock class might render those unnecessary (or just more manually spying).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zacronos yea, not getting that quoting to work any other way. ill catch up w/ you in chat.

@zacronos
Copy link
Member

LGTM, though I'd like to see the extra escapes removed for readability

@realtyjustin
Copy link
Contributor Author

cool ok, so we got to the bottom of the string dilemma... i was adding extra slashes, and only needed one set of double-slash. Anyways, moot point now as I've removed those longer strings in lieu of the fact that those tests already test if insert or where or whatever is calledOnce, and test using calledWith, so any more testing beyond that would be like testing knex query build output which is redundant.

@jessecstewart
Copy link
Contributor

LGTM

zacronos pushed a commit that referenced this pull request Nov 11, 2015
@zacronos zacronos merged commit 4320029 into realtymaps:master Nov 11, 2015
@@ -0,0 +1,148 @@
_ = require 'lodash'
tables = require '../../backend/config/tables'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice 🎱

@zacronos zacronos deleted the dev/jet/MAPD-645/rulecrud_spec branch December 1, 2015 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants