mirror of
https://github.com/Foundry376/Mailspring.git
synced 2025-10-04 10:28:46 +08:00
fix(db-spec): Accompanying spec changes
This commit is contained in:
parent
9eea7f52b9
commit
a84b95359c
1 changed files with 21 additions and 31 deletions
|
@ -81,7 +81,6 @@ describe "QuerySubscription", ->
|
||||||
]
|
]
|
||||||
mustUpdate: false
|
mustUpdate: false
|
||||||
mustTrigger: true
|
mustTrigger: true
|
||||||
mustRefetchAllIds: false
|
|
||||||
},{
|
},{
|
||||||
name: 'Item in set saved - new sort value'
|
name: 'Item in set saved - new sort value'
|
||||||
change:
|
change:
|
||||||
|
@ -94,9 +93,8 @@ describe "QuerySubscription", ->
|
||||||
new Thread(accountId: 'a', clientId: '3', lastMessageReceivedTimestamp: 3),
|
new Thread(accountId: 'a', clientId: '3', lastMessageReceivedTimestamp: 3),
|
||||||
new Thread(accountId: 'a', clientId: '2', lastMessageReceivedTimestamp: 2),
|
new Thread(accountId: 'a', clientId: '2', lastMessageReceivedTimestamp: 2),
|
||||||
]
|
]
|
||||||
mustUpdate: false
|
mustUpdate: true
|
||||||
mustTrigger: true
|
mustTrigger: true
|
||||||
mustRefetchAllIds: true
|
|
||||||
},{
|
},{
|
||||||
name: 'Item saved - does not match query clauses, offset > 0'
|
name: 'Item saved - does not match query clauses, offset > 0'
|
||||||
change:
|
change:
|
||||||
|
@ -105,7 +103,6 @@ describe "QuerySubscription", ->
|
||||||
type: 'persist'
|
type: 'persist'
|
||||||
nextModels: 'unchanged'
|
nextModels: 'unchanged'
|
||||||
mustUpdate: true
|
mustUpdate: true
|
||||||
mustRefetchAllIds: true
|
|
||||||
},{
|
},{
|
||||||
name: 'Item saved - matches query clauses'
|
name: 'Item saved - matches query clauses'
|
||||||
change:
|
change:
|
||||||
|
@ -113,7 +110,6 @@ describe "QuerySubscription", ->
|
||||||
objects: [new Thread(accountId: 'a', clientId: '5', lastMessageReceivedTimestamp: -2)]
|
objects: [new Thread(accountId: 'a', clientId: '5', lastMessageReceivedTimestamp: -2)]
|
||||||
type: 'persist'
|
type: 'persist'
|
||||||
mustUpdate: true
|
mustUpdate: true
|
||||||
mustRefetchAllIds: true
|
|
||||||
},{
|
},{
|
||||||
name: 'Item in set saved - no longer matches query clauses'
|
name: 'Item in set saved - no longer matches query clauses'
|
||||||
change:
|
change:
|
||||||
|
@ -126,7 +122,6 @@ describe "QuerySubscription", ->
|
||||||
new Thread(accountId: 'a', clientId: '1', lastMessageReceivedTimestamp: 1),
|
new Thread(accountId: 'a', clientId: '1', lastMessageReceivedTimestamp: 1),
|
||||||
]
|
]
|
||||||
mustUpdate: true
|
mustUpdate: true
|
||||||
mustRefetchAllIds: false
|
|
||||||
},{
|
},{
|
||||||
name: 'Item in set deleted'
|
name: 'Item in set deleted'
|
||||||
change:
|
change:
|
||||||
|
@ -139,7 +134,6 @@ describe "QuerySubscription", ->
|
||||||
new Thread(accountId: 'a', clientId: '1', lastMessageReceivedTimestamp: 1),
|
new Thread(accountId: 'a', clientId: '1', lastMessageReceivedTimestamp: 1),
|
||||||
]
|
]
|
||||||
mustUpdate: true
|
mustUpdate: true
|
||||||
mustRefetchAllIds: false
|
|
||||||
},{
|
},{
|
||||||
name: 'Item not in set deleted'
|
name: 'Item not in set deleted'
|
||||||
change:
|
change:
|
||||||
|
@ -148,7 +142,6 @@ describe "QuerySubscription", ->
|
||||||
type: 'unpersist'
|
type: 'unpersist'
|
||||||
nextModels: 'unchanged'
|
nextModels: 'unchanged'
|
||||||
mustUpdate: false
|
mustUpdate: false
|
||||||
mustRefetchAllIds: false
|
|
||||||
}]
|
}]
|
||||||
|
|
||||||
},{
|
},{
|
||||||
|
@ -174,7 +167,6 @@ describe "QuerySubscription", ->
|
||||||
objects: [new Thread(accountId: 'a', clientId: '3', lastMessageReceivedTimestamp: 1, unread: true)]
|
objects: [new Thread(accountId: 'a', clientId: '3', lastMessageReceivedTimestamp: 1, unread: true)]
|
||||||
type: 'persist'
|
type: 'persist'
|
||||||
mustUpdate: true
|
mustUpdate: true
|
||||||
mustRefetchAllIds: true
|
|
||||||
}]
|
}]
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
@ -193,31 +185,29 @@ describe "QuerySubscription", ->
|
||||||
subscription._updateInFlight = false
|
subscription._updateInFlight = false
|
||||||
subscription.applyChangeRecord(test.change)
|
subscription.applyChangeRecord(test.change)
|
||||||
|
|
||||||
if test.mustRefetchAllIds
|
if test.mustUpdate
|
||||||
expect(subscription._set).toBe(null)
|
expect(subscription.update).toHaveBeenCalledWith({mustRefetchEntireRange: true})
|
||||||
else if test.nextModels is 'unchanged'
|
else
|
||||||
|
if test.nextModels is 'unchanged'
|
||||||
expect(subscription._set.models()).toEqual(scenario.lastModels)
|
expect(subscription._set.models()).toEqual(scenario.lastModels)
|
||||||
else
|
else
|
||||||
expect(subscription._set.models()).toEqual(test.nextModels)
|
expect(subscription._set.models()).toEqual(test.nextModels)
|
||||||
|
|
||||||
if test.mustUpdate
|
|
||||||
expect(subscription.update).toHaveBeenCalled()
|
|
||||||
|
|
||||||
if test.mustTriger
|
if test.mustTriger
|
||||||
expect(subscription._createResultAndTrigger).toHaveBeenCalled()
|
expect(subscription._createResultAndTrigger).toHaveBeenCalled()
|
||||||
|
|
||||||
describe "update", ->
|
describe "update", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
spyOn(QuerySubscription.prototype, '_fetchMissingRange').andCallFake ->
|
spyOn(QuerySubscription.prototype, '_fetchRange').andCallFake ->
|
||||||
@_set ?= new MutableQueryResultSet()
|
@_set ?= new MutableQueryResultSet()
|
||||||
Promise.resolve()
|
Promise.resolve()
|
||||||
|
|
||||||
describe "when the query has an infinite range", ->
|
describe "when the query has an infinite range", ->
|
||||||
it "should call _fetchMissingRange for the entire range", ->
|
it "should call _fetchRange for the entire range", ->
|
||||||
subscription = new QuerySubscription(DatabaseStore.findAll(Thread))
|
subscription = new QuerySubscription(DatabaseStore.findAll(Thread))
|
||||||
subscription.update()
|
subscription.update()
|
||||||
advanceClock()
|
advanceClock()
|
||||||
expect(subscription._fetchMissingRange).toHaveBeenCalledWith(QueryRange.infinite(), {fetchEntireModels: true, version: 1})
|
expect(subscription._fetchRange).toHaveBeenCalledWith(QueryRange.infinite(), {fetchEntireModels: true, version: 1})
|
||||||
|
|
||||||
it "should fetch full full models only when the previous set is empty", ->
|
it "should fetch full full models only when the previous set is empty", ->
|
||||||
subscription = new QuerySubscription(DatabaseStore.findAll(Thread))
|
subscription = new QuerySubscription(DatabaseStore.findAll(Thread))
|
||||||
|
@ -225,23 +215,23 @@ describe "QuerySubscription", ->
|
||||||
subscription._set.addModelsInRange([new Thread()], new QueryRange(start: 0, end: 1))
|
subscription._set.addModelsInRange([new Thread()], new QueryRange(start: 0, end: 1))
|
||||||
subscription.update()
|
subscription.update()
|
||||||
advanceClock()
|
advanceClock()
|
||||||
expect(subscription._fetchMissingRange).toHaveBeenCalledWith(QueryRange.infinite(), {fetchEntireModels: false, version: 1})
|
expect(subscription._fetchRange).toHaveBeenCalledWith(QueryRange.infinite(), {fetchEntireModels: false, version: 1})
|
||||||
|
|
||||||
describe "when the query has a range", ->
|
describe "when the query has a range", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@query = DatabaseStore.findAll(Thread).limit(10)
|
@query = DatabaseStore.findAll(Thread).limit(10)
|
||||||
|
|
||||||
describe "when we have no current range", ->
|
describe "when we have no current range", ->
|
||||||
it "should call _fetchMissingRange for the entire range and fetch full models", ->
|
it "should call _fetchRange for the entire range and fetch full models", ->
|
||||||
subscription = new QuerySubscription(@query)
|
subscription = new QuerySubscription(@query)
|
||||||
subscription._set = null
|
subscription._set = null
|
||||||
subscription.update()
|
subscription.update()
|
||||||
advanceClock()
|
advanceClock()
|
||||||
expect(subscription._fetchMissingRange).toHaveBeenCalledWith(@query.range(), {fetchEntireModels: true, version: 1})
|
expect(subscription._fetchRange).toHaveBeenCalledWith(@query.range(), {fetchEntireModels: true, version: 1})
|
||||||
|
|
||||||
describe "when we have a previous range", ->
|
describe "when we have a previous range", ->
|
||||||
|
|
||||||
it "should call _fetchMissingRange with the missingRange", ->
|
it "should call _fetchRange with the missingRange", ->
|
||||||
customRange = jasmine.createSpy('customRange1')
|
customRange = jasmine.createSpy('customRange1')
|
||||||
spyOn(QueryRange, 'rangesBySubtracting').andReturn [customRange]
|
spyOn(QueryRange, 'rangesBySubtracting').andReturn [customRange]
|
||||||
subscription = new QuerySubscription(@query)
|
subscription = new QuerySubscription(@query)
|
||||||
|
@ -249,14 +239,14 @@ describe "QuerySubscription", ->
|
||||||
subscription._set.addModelsInRange([new Thread()], new QueryRange(start: 0, end: 1))
|
subscription._set.addModelsInRange([new Thread()], new QueryRange(start: 0, end: 1))
|
||||||
|
|
||||||
advanceClock()
|
advanceClock()
|
||||||
subscription._fetchMissingRange.reset()
|
subscription._fetchRange.reset()
|
||||||
subscription._updateInFlight = false
|
subscription._updateInFlight = false
|
||||||
subscription.update()
|
subscription.update()
|
||||||
advanceClock()
|
advanceClock()
|
||||||
expect(subscription._fetchMissingRange.callCount).toBe(1)
|
expect(subscription._fetchRange.callCount).toBe(1)
|
||||||
expect(subscription._fetchMissingRange.calls[0].args).toEqual([customRange, {fetchEntireModels: true, version: 1}])
|
expect(subscription._fetchRange.calls[0].args).toEqual([customRange, {fetchEntireModels: true, version: 1}])
|
||||||
|
|
||||||
it "should call _fetchMissingRange for the entire query range when the missing range encompasses more than one range", ->
|
it "should call _fetchRange for the entire query range when the missing range encompasses more than one range", ->
|
||||||
customRange1 = jasmine.createSpy('customRange1')
|
customRange1 = jasmine.createSpy('customRange1')
|
||||||
customRange2 = jasmine.createSpy('customRange2')
|
customRange2 = jasmine.createSpy('customRange2')
|
||||||
spyOn(QueryRange, 'rangesBySubtracting').andReturn [customRange1, customRange2]
|
spyOn(QueryRange, 'rangesBySubtracting').andReturn [customRange1, customRange2]
|
||||||
|
@ -267,9 +257,9 @@ describe "QuerySubscription", ->
|
||||||
subscription._set.addModelsInRange([new Thread()], range)
|
subscription._set.addModelsInRange([new Thread()], range)
|
||||||
|
|
||||||
advanceClock()
|
advanceClock()
|
||||||
subscription._fetchMissingRange.reset()
|
subscription._fetchRange.reset()
|
||||||
subscription._updateInFlight = false
|
subscription._updateInFlight = false
|
||||||
subscription.update()
|
subscription.update()
|
||||||
advanceClock()
|
advanceClock()
|
||||||
expect(subscription._fetchMissingRange.callCount).toBe(1)
|
expect(subscription._fetchRange.callCount).toBe(1)
|
||||||
expect(subscription._fetchMissingRange.calls[0].args).toEqual([@query.range(), {fetchEntireModels: true, version: 1}])
|
expect(subscription._fetchRange.calls[0].args).toEqual([@query.range(), {fetchEntireModels: true, version: 1}])
|
||||||
|
|
Loading…
Add table
Reference in a new issue