2015-06-26 22:42:41 +08:00
TestModel = require ' ../fixtures/db-test-model '
Attributes = require ' ../../src/flux/attributes '
2015-07-31 09:09:20 +08:00
DatabaseSetupQueryBuilder = require ' ../../src/flux/stores/database-setup-query-builder '
2015-06-26 22:42:41 +08:00
2015-07-31 09:09:20 +08:00
describe " DatabaseSetupQueryBuilder " , ->
2015-06-26 22:42:41 +08:00
beforeEach ->
2015-07-31 09:09:20 +08:00
@builder = new DatabaseSetupQueryBuilder ( )
2015-06-26 22:42:41 +08:00
2015-07-31 09:09:20 +08:00
describe " setupQueriesForTable " , ->
2015-06-26 22:42:41 +08:00
it " should return the queries for creating the table and the primary unique index " , ->
TestModel.attributes =
' attrQueryable ' : Attributes . DateTime
queryable: true
modelKey: ' attrQueryable '
jsonKey: ' attr_queryable '
' attrNonQueryable ' : Attributes . Collection
modelKey: ' attrNonQueryable '
jsonKey: ' attr_non_queryable '
2015-07-31 09:09:20 +08:00
queries = @ builder . setupQueriesForTable ( TestModel )
2015-06-26 22:42:41 +08:00
expected = [
' CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,attr_queryable INTEGER) ' ,
' CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`) '
]
for query , i in queries
expect ( query ) . toBe ( expected [ i ] )
it " should correctly create join tables for models that have queryable collections " , ->
TestModel . configureWithCollectionAttribute ( )
2015-07-31 09:09:20 +08:00
queries = @ builder . setupQueriesForTable ( TestModel )
2015-06-26 22:42:41 +08:00
expected = [
2015-08-29 02:12:53 +08:00
' CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,client_id TEXT,server_id TEXT) ' ,
2015-06-26 22:42:41 +08:00
' CREATE UNIQUE INDEX IF NOT EXISTS `TestModel_id` ON `TestModel` (`id`) ' ,
2016-04-05 08:44:45 +08:00
' CREATE TABLE IF NOT EXISTS `TestModelCategory` (id TEXT KEY, `value` TEXT) '
2016-04-05 09:21:39 +08:00
' CREATE INDEX IF NOT EXISTS `TestModelCategory_id` ON `TestModelCategory` (`id` ASC) '
' CREATE UNIQUE INDEX IF NOT EXISTS `TestModelCategory_val_id` ON `TestModelCategory` (`value` ASC, `id` ASC) ' ,
2015-06-26 22:42:41 +08:00
]
for query , i in queries
expect ( query ) . toBe ( expected [ i ] )
it " should use the correct column type for each attribute " , ->
TestModel . configureWithAllAttributes ( )
2015-07-31 09:09:20 +08:00
queries = @ builder . setupQueriesForTable ( TestModel )
2015-06-26 22:42:41 +08:00
expect ( queries [ 0 ] ) . toBe ( ' CREATE TABLE IF NOT EXISTS `TestModel` (id TEXT PRIMARY KEY,data BLOB,datetime INTEGER,string-json-key TEXT,boolean INTEGER,number INTEGER) ' )
describe " when the model provides additional sqlite config " , ->
it " the setup method should return these queries " , ->
TestModel . configureWithAdditionalSQLiteConfig ( )
spyOn ( TestModel . additionalSQLiteConfig , ' setup ' ) . andCallThrough ( )
2015-07-31 09:09:20 +08:00
queries = @ builder . setupQueriesForTable ( TestModel )
2015-06-26 22:42:41 +08:00
expect ( TestModel . additionalSQLiteConfig . setup ) . toHaveBeenCalledWith ( )
feat(accounts): Kill namespaces, long live accounts
Summary:
This diff replaces the Namespace object with the Account object, and changes all references to namespace_id => account_id, etc. The endpoints are now `/threads` instead of `/n/<id>/threads`.
This diff also adds preliminary support for multiple accounts. When you log in, we now log you in to all the attached accounts on edgehill server. From the preferences panel, you can auth with / unlink additional accounts. Shockingly, this all seems to pretty much work.
When replying to a thread, you cannot switch from addresses. However, when creating a new message in a popout composer, you can change the from address and the SaveDraftTask will delete/re-root the draft on the new account.
Search bar doesn't need to do full refresh on clear if it never committed
Allow drafts to be switched to a different account when not in reply to an existing thread
Fix edge case where ChangeMailTask throws exception if no models are modified during performLocal
Show many dots for many accounts in long polling status bar
add/remove accounts from prefs
Spec fixes!
Test Plan: Run tests, none broken!
Reviewers: evan, dillon
Reviewed By: evan, dillon
Differential Revision: https://phab.nylas.com/D1928
2015-08-22 06:29:58 +08:00
expect ( queries . pop ( ) ) . toBe ( ' CREATE INDEX IF NOT EXISTS ThreadListIndex ON Thread(last_message_received_timestamp DESC, account_id, id) ' )
2015-06-26 22:42:41 +08:00
it " should not fail if additional config is present, but setup is undefined " , ->
delete TestModel . additionalSQLiteConfig [ ' setup ' ]
@m = new TestModel ( id: ' local-6806434c-b0cd ' , body: ' hello world ' )
2015-07-31 09:09:20 +08:00
expect ( => @ builder . setupQueriesForTable ( TestModel ) ) . not . toThrow ( )