Mike Gerwitz

Activist for User Freedom

path: root/test
Commit message (Collapse)AuthorAgeFilesLines
* RatingServiceTest: Add type information for stubsMike Gerwitz2019-10-291-5/+149
| | | | | | | This also gets rid of the RatingServiceStub module, which is not used by anything else. I suspect that I originally added it to be shared by traits, but that's no longer going to be the case (and the only remaining trait is unfortunately untested atm, and will be going away).
* RatingService: Convert to TypeScriptMike Gerwitz2019-10-291-11/+8
| | | | | | | | | | | | | | | This was an adventure, and was also used as a peer programming exercise to introduce TypeScript to other programmers in the office. This class has far too many dependencies, which made this difficult. The approach was to create .d.ts files for dependencies and wait on moving those over for now, otherwise the task will never get done. The RatingServicePublic trait was left as such for the time being; I was able to work around a bug that was making it difficult to mix it into a prototype. There were no logic changes; this was just type refactoring.
* src/numeric: New moduleMike Gerwitz2019-10-241-0/+59
| | | | | | This beings to introduce compile-time safety for numeric values under the assumption that they are enforced by the runtime. See docblock for more information.
* RatingServiceSubmitNotify: Remove unused traitMike Gerwitz2019-10-211-186/+0
* {src,test}/.npmignore: New filesMike Gerwitz2019-10-211-0/+2
| | | | | | NPM was not publishing the compiled JS files (from the TS input) because they were present in generated .gitignore files. .npmignore takes precedence.
* TokenedDataApi: Accept or kill tokenMike Gerwitz2019-10-181-3/+12
| | | | | | | | | | | Rather than leaving a token in a DONE state, we should either transition to ACCEPTED or DEAD depending on whether the token was superceded. * src/server/dapi/TokenedDataApi.ts (_replyUnlessStale): Accept token when not superceded, otherwise kill. [store]: New param. (request): Use it. * test/server/dapi/TokenedDataApiTest.ts: Update accordingly.
* Integrate TokenedDataApi into systemMike Gerwitz2019-10-184-5/+5
| | | | | | | | | | | | | | | | | This changes the easejs interface for DataApi, which requires adding the param to everything. The TS interface was created in a previous commit and already contained this parameter. The idea is to remove the easejs interface in the future, but traits are a barrier to that atm. DocumentServer and controller demonstrate the mess that we have with regards to instantiating dependencies. This needs to change---DocumentServer itself was something that was started but never fully realized. It makes this incredibly confusing, difficult to follow, and complicates important error handling that ought to be taking place. It also discourages implementing additional dependencies. I'm not going to go through and provide a ChangeLog-style commit message for this commit. I'm too exhausted by this crap.
* NodeCallback<T, R>: New type to simplify callback declarationsMike Gerwitz2019-10-181-7/+7
| | | | | | | | | | Just trying to reduce some boilerplate. I kept this as a separate commit to illustrate clearly how this type of things is done since we'll have people learning TypeScript. * src/types/misc.ts (NodeCallback<T,R>): New type. * src/server/dapi/TokenedDataApi.ts: Use it. * test/server/dapi/TokenedDataApiTest.ts: Use it.
* TokenedDataApi: New classMike Gerwitz2019-10-181-0/+233
| | | | | | | | | | | | | | | | | This integrates the PersistentTokenStore into the DataAPI system via a decorator. Unfortunately, it requires an API change and propagating data through the system is a huge mess, which is the topic of a following commit. The API modification was a compromise. This modifies the interface of DataApi to include a third parameter. I am continuing to export the old easejs interface for an incremental migration away from it. That old interface will be modified next commit, since it requires modifying a lot of files and will muddy up this commit. * src/dapi/DataApi.ts: Rename from js. Add types. Add new interface. Continue exporting old. * src/server/dapi/TokenedDataApi.ts: New class. * test/server/dapi/TokenedDataApiTest.ts: New test cases.
* {=>Persistent}TokenStoreMike Gerwitz2019-10-181-6/+9
| | | | | | | | | | | This creates an interface for TokenStore. The main motivation of this right now is testing, since I'm punting on figuring out a mock framework right now (due to time constraints). * src/server/token/TokenStore.ts: Rename file. * src/server/token/store/PersistentTokenStore.ts: Rename from TokenStore. * test/server/token/TokenStoreTest.ts: Rename file. * test/server/token/store/PersistentTokenStoreTest.ts: Rename from TokenStoreTest.
* TokenDao, TokenStore: Track most recently created tokensMike Gerwitz2019-10-182-3/+77
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is much more useful information than the last modified. For example: - Token A is created. It becomes the last modified. - Token B is created. It becomes the last modified. - Token A completes. Mismatch. It becomes the last modified. - Token B completes. Mismatch. It becomes the last modified. So in this case, we're unable to use the flag to determine whether we should ignore the token. But if we instead us the new flag to see what token was last _created_, the problem is solved. This should have been obvious the first time around. * src/server/token/MongoTokenDao.ts (updateToken): Query `lastState'. Return its value. Update its value. (getToken): Query lastState. Return its value. * src/server/token/Token.ts (Token)[last_state]: New field. * src/server/token/TokenDao.ts (TokenQueryResult, TokenNamespaceResults): Use type instead of interface. (TokenStateHistory): New type. (TokenNamespaceData)[lastState]: New optional field. (TokenData)[prev_state]: New field. * src/server/token/TokenStore.ts: Return previous state data for each method. * test/server/token/MongoTokenDaoTest.ts: Add last_state. * test/server/token/TokenStoreTest.ts: Likewise.
* TokenStore: Provide document id via constructorMike Gerwitz2019-10-181-8/+8
| | | | | | | | | | | | | | | | | | The primary use case for this is currently the DataAPI, and the quote id is only available at the highest level of the server, before dapis are processed. In any case, the TokenStore was already described in terms of a combination of document id; namespace; and root field; so it makes sense for doc id to be part of the constructor. If a more generic TokenStore is needed in the future, we could go back to the previous API and wrap it in another class, like a partially applied function (e.g. `DocumentTokenStore`). * src/server/token/TokenStore.ts: Move doc_id out of arguments and into the constructor. * test/server/token/TokenStoreTest.ts: Update accordingly.
* TokenStore: Implement for token lookups and creationMike Gerwitz2019-10-181-0/+395
| | | | | | | | | Does not yet support token updates. * src/server/token/Token.ts (TokenStateDeadable, TokenStateDoneable, TokenStateAcceptable, Token): New types. * src/server/token/TokenStore.ts: New class. * test/server/token/TokenStoreTest.ts: New test case.
* TokenDao: Return previous stateMike Gerwitz2019-10-181-42/+221
| | | | | | | | | | | | | | | | | | | | | | | | | This causes the DAO to return the state of the document prior to the database operation (in the case of a retrieval, the previous state is the same as the current state). This will allow determining whether other tokens were modified since a previous request. * src/server/token/MongoTokenDao.ts: Stop using TokenType in favor of new TokenState. (updateToken): Query for and return previous state. Use findAndModify instead of update. (getToken): Return previous state. Minor changes to account for new TokenQueryResult types (null=>undefined). * src/server/token/Token.ts: Add comments for existing Token{Id,Namespace} nominal types. (TokenState): New string enum. * src/server/token/TokenDao.ts: Import new TokenState. (TokenDao)[updateToken]: Use it. (TokenType): Remove. (TokenQueryResult, TokenNamespaceResults, TokenNamespaceData): null=>undefined for unavailable value. null was wrong. (TokenStatus): Token{Type=>State}. (TokenData)[prev_state, prev_status]: New fields. * test/server/token/MongoTokenDaoTest.ts: Update tests accordingly.
* TokenDao (#updateToken): Return updated dataMike Gerwitz2019-10-181-2/+11
| | | | | | | | | | | Since some of these data are generated within TokenDao (e.g. the timestamp), the caller cannot infer all values. * src/server/token/MongoTokenDao.ts (updateToken): Return Promise<{void=>TokenData}>. * src/server/token/TokenDao.ts (TokenDao)[#updateToken]: Update interface accordingly. * test/server/token/MongoTokenDaoTest.ts: Update test accordingly.
* TokenDao: Add error contextMike Gerwitz2019-10-181-4/+36
* {Context,Chained}Error: New modulesMike Gerwitz2019-10-182-0/+135
| | | | | This will allow us to provide additional useful information for structure logging.
* TokenDao: Better error handling for unknown tokensMike Gerwitz2019-10-171-10/+46
| | | | | | | | | | | | | | | | | | | | | | | Rather than replying with null, which complicates using the returned promise efficiently, we'll respond with a unique error that allows us to distinguish between a database failure and a missing token. These are more traditional errors, but we're moving toward structured logging, so I want error objects that provide more context. I'll explore that a bit more in next commit. Unfortunately, the untypedness of Promise rejections make for a less than desirable situation here. Async/await is not yet an option since we're still compiling to ES5 (have to support IE11), and TS compiles async/await into generators for environments that don't support them, which also are not available in ES5. * src/server/service/TokenedService.js (_getQuoteToken): Remove null check, since this situation can no longer occur. * src/server/token/MongoTokenDao.ts (getToken): Remove null from return type union; reject with `UnknownTokenError' instead. * src/server/token/TokenDao.ts: Modify interface accordingly. * src/server/token/UnknownTokenError.ts: New class. * test/server/token/MongoTokenDaoTest.ts: Modify tests accordingly. Add missing test for latest token namespace missing.
* TokenDao: class=>interfaceMike Gerwitz2019-10-171-5/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | TokenDao has been renamed to MongoTokenDao. While it's good for this to have its own interface anyway, the immediate motivation was for unit tests: I started playing with mocking with TypeScript and researching some libraries, but I don't have time to research enough to commit to any of them at the moment. Interfaces remove the need to mock at all. This also stops using `export default' in favor of just importing by name. Using defaults only saves us a few characters, and it makes for awkward syntax in various cases (e.g. with multiple exports). But I'm still new to TS, so who knows if I'll be flip-flopping on this decision in the future. If we kept to our normal 1:1 file:definition convention, it wouldn't cause problems, but based on the types I've had to define so far, that'd cause way too much bloat and boilerplate. * src/server/daemon/controller.js: No long import `default'. Use `MongoTokenDao'. * src/server/token/TokenedService.js: Stop checking type (since TS interfaces do not result in compiler output, easejs cannot validate against them.) * src/server/token/MongoTokenDao.ts: Rename from `TokenDao.ts'. * src/server/token/TokenDao.ts: Rename from `TokenQueryResult.ts'. (TokenDao): New interface. * src/server/token/TokenQueryResult.ts: Rename to `TokenDao.ts'. * test/server/token/MongoTokenDaoTest.ts: Rename from `TokenDaoTest.ts'.
* TokenDao: "quote"=>"document" with nominal typeMike Gerwitz2019-10-171-7/+13
| | | | | | * src/document/Document.ts: New file. * src/server/token/TokenDao.ts: quote=>document and use DocumentId. * test/server/token/TokenDaoTest.ts: Likewise.
* TokenDao: Nominal typingMike Gerwitz2019-10-171-22/+28
| | | | | | | | | | | | | This beings an experiment with nominal typing using what the TS community calls "branding". The lack of nominal types was one of my biggest disappointments with TS, so this should really help to mitigate bugs resulting from misappropriation of data. * src/server/token/Token.ts: New file. * src/server/token/TokenDao.ts: Use Token{Id,Namespace}. * src/server/token/TokenQueryResult.ts: Likewise. * src/types/misc.d.ts: Introduce NominalType and UnixTimestamp. * test/server/token/TokenDaoTest.ts: Use nominal types.
* TokenDao: Lift out nondeterminism (date)Mike Gerwitz2019-10-171-12/+13
| | | | | | | | | | * src/server/daemon/controller.js (getUnixTimestamp): New method. Not ideal, but better than where it was. (_initExportService): Pass to TokenDao constructor. * src/server/token/TokenDao.ts (_getTimestamp): New field. (constructor)[get_timestamp]: New param. (updateToken): Use it. * test/server/token/TokenDaoTest.ts: Provide stub timestamp function.
* TokenDao: Export as default alongside TokenDataMike Gerwitz2019-10-171-5/+6
| | | | | | | | | | | | | | | | | | | Our coding standards are to create a separate file for classes and interfaces, but this is a bit different: this "interface" is more like a struct, and it's used to define the return type of a method of this class. Since it's inherently coupled, I'm keeping it in the same file. The idea is that the caller will provide its own abstraction rather than continuing to export this one. Note that Typescript does support re-exporting symbols if need be. * src/server/daemon/controller.js: Adjust import of TokenDao (TS compiles default modules as `default'). * src/server/service/TokenedService.js: Adjust import of TokenDao. * src/server/token/TokenDao.ts: Export TokenDao as `default'. Export TokenData. * test/server/token/TokenDaoTest.ts: Adjust import of TokenDao. Import TokenData.
* TokenDao: Callbacks=>promisesMike Gerwitz2019-10-171-29/+18
| | | | | | | | | | | | This makes minimal changes to TokenedService, even though there is obvious refactoring that can be done to reduce duplication, because the class is currently untested. * src/server/service/TokenedService.js (_getQuoteToken, generateToken, killToken, acceptToken, completeToken): Expect promise. * src/server/token/TokenDao.ts (updateToken, getToken): Remove callback param, return Promise. * test/server/token/TokenDaoTest.ts: Use promises.
* TokenDao: Add test and further refine typesMike Gerwitz2019-10-171-0/+243
| | | | | | | | | | | | | | | | | | | This tests the existing state of TokenDao before additional modifications are made. This commit also further refines the types introduced in a previous commit. This is also the first test written in Typescript. * package.json.in (devDependencies): Add node, chai, and mocha types. * src/server/token/TokenDao.ts (updateToken): `data` accepts null (as it should). Do not conditionall add data to object (it doesn't matter for later retrieval). Note nondeterminism with date. More concise syntax for object fields. * src/server/token/TokenQueryResult.ts: Make all fields readonly. (TokenStatus): Date is no longer optional (see above mention). * src/types/mongodb.d.ts: Remove generics (erroneously added). (Collection)[update]: Remove 3-argument declaration (see comment). * test/server/token/TokenDaoTest.ts: New test case.
* FieldVisibilityEventHandler: Fix arrow function notationMike Gerwitz2019-10-171-1/+1
| | | | This was a syntax recognized back in the day.
* [DEV-5657] Check for TLD in email addressesJoseph Frazer2019-09-121-0/+63
| | | | | The DocuSign service rejects email addresses without a TLD, even though they are valid.
* Copyright range updateMike Gerwitz2019-08-3057-57/+57
| | | | | All files now have the same range, beginning from the conception of this project.
* [DEV-5546] Change getdate to getUTCDateSarah Chintomby2019-06-181-1/+1
* [DEV-5546] Fix calc relativedate for day and also month concerning edge casesSarah Chintomby2019-06-181-0/+72
* [DEV-5333] Pass last rated date from the server quote back to the client quoteAustin Schaffer2019-06-174-19/+237
| | | | Correct and add more elaborate tests for RateEventHandler
* [DEV-5333] Expose initialRatedDate to the client from the bucketAustin Schaffer2019-06-142-1/+82
| | | | | | | | | | | | | | [DEV-5333] WIP Add RateEventHandlerTest and fix RatingServiceSubmitNotifyTest WIP: Add RateEventHandlerTest Add stubs for RateEventHandlerTest Finish RateEventHandlerTest Move done to fix test bug
* [DEV-3514] Fix bug with expiration date calculationAndrew Fanton2019-05-301-36/+37
| | | | | | | | | | The nature of this bug was two-fold: 1.) A new Date was being instantiated with seconds, but the constructor expects milliseconds. 2.) The expiration period was not cast to a number, causing an expression to concatenate strings instead of adding numeric values; this greatly increased the actual expiration date.
* [DEV-3514] Display message explaining why quote is lockedAndrew Fanton2019-05-281-4/+10
| | | | | | Prior to this change, a single generic message was always shown simply stating that the quote had been locked. These changes now allow for different messages to be displayed in different circumstances.
* [DEV-3514] Lock quotes that exceed expiration dateAndrew Fanton2019-05-282-6/+312
* [DEV-3514] Add more robust testing for BasicQuoteCorey Vollmer2019-05-211-22/+188
| | | | Also, updated README to include instructions on `npm install.`
* db: Restore previous save-all-meta behaviorMike Gerwitz2019-02-121-0/+123
| | | | | | | | | | | | | | It looks like the metabucket is never initialized, so saving the quote is right now the only thing that sets default values. That should be fixed in the future. This also begins adding tests for the terrible MongoServerDao, that could use some refactoring. * src/server/db/MongoServerDao.js: Make `meta' mutable. I had forgotten to remove the code that mutates it (since our version of v8 right now does not blow up for const assignments), so this is all that's needed. * test/server/db/MongoServerDaoTest.js: New file to test this situation.
* [DEV-4338] Change behavior of default dataJoseph Frazer2019-02-041-1/+64
| | | | | | Default data was converted to an empty array if the data evaluated to false. We only want to convert it if it is undefined so values that are false remain false.
* dapi: Fix *_label settingMike Gerwitz2018-12-171-1/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | The `*_label' fields were not being properly set because they were being considered just as every other expanded field, which is subject to other considerations to ensure that we do not overwrite user data. Label fields, on the other hand, _must_ always be set whenever the value changes, and are _not_ modifiable by the user. This codifies that `_label' assumption that I would like removed in the future, but time does not permit that sort of refactoring right now. Ideally, labels would be treated generically like any other expanded field and have an attribute set of them that would change their expansion behavior. * src/client/dapi/DataApiMediator.js (_updateFieldData): Pass label field id to `_populateWithMap'. (_populateWithMap): Use it to always populate the label field when the key matches, ignoring the other expansion criteria that would inhibit it. * test/client/dapi/DataApiMediatorTest.js: Update test accordingly. * src/dapi/DataApiManager.js (triggerFieldUpdate): Provide id to `_genUiFieldData'. (_genUiFieldData)[label_id]: New field. Return it as part of the return object's `label_id' field. DEV-4077
* Accommodate ancient qtype data on init and cleanMike Gerwitz2018-11-192-1/+24
| | | | | | | | | * src/program/ProgramInit.js (_isKnownType): Account for ancient qtype representation (as a string). * src/server/quote/ProgramQuoteCleaner.js (_isKnownType): Likewise. * test/program/ProgramInitTest.js: New test case for this situation. * test/server/quote/ProgramQuoteCleanerTest.js: Modify existing test case for this situation.
* ProgramInit: Do not initialize bucket values for undefined question typesMike Gerwitz2018-11-142-12/+60
| | | | | | | | | | | | | | | | | | | | | | | | These denote fields that are generated but do not actually have any data associated with them. For example, select options with predicates have a field generated so that they contribute to the group field count (so that the group will automatically show/hide appropriately), but those should never have values associated with them in the bucket. This was manifesting as a nasty bug: The bucket contained a key for generated options. When the quote is loaded, the client "empties" the bucket. In doing so, it set the option value to the empty string, which had the effect of rendering the dropdown useless---every value was the empty string! * src/program/ProgramInit.js (_isKnownType): New method. (init): Use it and ignore fields with unknown types. * src/server/Server.js: Add note that we shouldn't have this logic duplicated between ProgramInit and ProgramQuoteCleaner. * src/server/quote/ProgramQuoteCleaner.js (_fixGroup): Ignore fields with unknown types. (_isKnownType): New method. * test/program/ProgramInitTest.js: Update existing tests. Add new. * test/server/quote/ProgramQuoteCleanerTest.js: Test this case.
* ProgramQuoteCleaner: Clean all groups (not just linked)Mike Gerwitz2018-10-211-3/+70
| | | | | | | | | | | * src/server/quote/ProgramQuoteCleaner.js (clean): Add docblock. Replace previous linked group cleaning with call to `_fixGroup'. (_fixGroup): New method. Similar logic to previous linked group cleaning, except that fields are never truncated. (_fixLinkedGroups, _getLinkedIndexLength): Remove methods. (_getGroupLength): New method determining group size from leader length, which also accounts for linked groups. * test/server/quote/ProgramQuoteCleanerTest.js: New test case.
* [DEV-3393] Made sure the entity id is a numberJoseph Frazer2018-08-162-2/+2
* [DEV-3393] minor changes to improve code qualityJoseph Frazer2018-08-152-50/+31
* [DEV-3393] Add more metadata to the init endpointJoseph Frazer2018-08-152-0/+151
* [bugfix] DapiMediator: Wait for stack to clear before updating optionsMike Gerwitz2018-08-101-0/+2
| | | | | | | This allows the UI to update before we add elements. This really isn't the best place to do this, but it will do for now. DEV-3257
* [DEV-3257] DataApiMediator: Set bucket data after stack clearMike Gerwitz2018-08-101-1/+10
| | | | | | | | | | | | | Allowing the stack to clear ensures that (in practice) DelayedStagingBucket is given a chance to do necessary processing before data are requested from it by bucket hooks as a result of _this_ invocation, which in turn results (in some cases) in infinite recursion. * src/client/dapi/DataApiMediator.js (_updateFieldData): Allow stack to clear before invoking `quote.setData'. * test/client/dapi/DataApiMediatorTest.js: Test respectively. DEV-3257
* [DEV-3257] DelayedStagingBucket: Preempt infinite recursion on #processValuesMike Gerwitz2018-08-101-0/+191
| | | | | | | | | | | | * src/bucket/DelayedRecursionError.js: New class. * src/bucket/DelayedStagingBucket.js: Update copyright and docblock. (_processing): New field. (getDataByName): Check against undefined before invoking `#processValues'. (processValues): Increment lock (_withProcessLock). (_withProcessLock): Error on recursion >= 5. DEV-3257
* DataApiMediator: Do not auto-expand into populated fieldsMike Gerwitz2018-07-171-12/+41
| | | | | | | | | | | * src/client/dapi/DataApiMediator.js (_populateWithMap): Update docblock. Ignore field during expansion if it would overwrite an existing value. * test/client/dapi/DataApiMediatorTest.js: Update tests data to include values for all bucket fields, not just `name'. Add test for new condition. DEV-3257
* [DEV-3257] DataApiMediator: Auto-expand into fields on reply [*]Mike Gerwitz2018-07-171-26/+204
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | [*] You should not use this commit directly since this may wipe out data in fields the user has changed. See future commit where this situation is properly handled. * src/client/Client (_init): Provide dapimap to DataApiMediator instance. * src/client/dapi/DataApiMediator.js (_dapi_map): New field. (constructor): Accept dapimap. BC break (which is okay, since this is still part of a topic branch). Assing to _dapi_map. Update docblock. (monitor): Bind `dapi_manager' to first argument of handlers. (_updateFieldData): Accept `dapi_manager' as first argument. Use `_populateWithMap' to generate additional update data. (_populateWithMap): New method. (_clearFieldFailures): Accept `dapi_manager' as first argument. * src/dapi/DataApiManager.js: Update copyright year. (getDataExpansion): Return empty object (consistent with interface) rather than `undefined' when field value is undefined. Use {Error=>MissingDataError} when field data are missing. Throw instead of emit. Fix missing comma in var declarations. * src/dapi/MissingDataError.js: New class. * test/client/dapi/DataApiMediatorTest.js: Update test data to test field expansion. New test against ignoring field expansion when data are not available. Update Sut constructors of other tests for new dapimap parameter. DEV-3257