@@ -21,10 +21,11 @@ import {
21
21
createOrUpgradeDb ,
22
22
DbTarget ,
23
23
DbTargetGlobal ,
24
- DbTargetGlobalKey
24
+ DbTargetGlobalKey , V1_STORES , V2_STORES
25
25
} from '../../../src/local/indexeddb_schema' ;
26
26
import { SimpleDb , SimpleDbTransaction } from '../../../src/local/simple_db' ;
27
27
import { PersistencePromise } from '../../../src/local/persistence_promise' ;
28
+ import { asyncQueue } from '../../integration/util/internal_helpers' ;
28
29
29
30
const INDEXEDDB_TEST_DATABASE = 'schemaTest' ;
30
31
@@ -88,11 +89,10 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
88
89
beforeEach ( ( ) => SimpleDb . delete ( INDEXEDDB_TEST_DATABASE ) ) ;
89
90
90
91
it ( 'can install schema version 1' , ( ) => {
91
- return withDb ( 1 , db => {
92
+ return withDb ( 1 , async db => {
92
93
expect ( db . version ) . to . equal ( 1 ) ;
93
94
// Version 1 adds all of the stores so far.
94
- expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
95
- return Promise . resolve ( ) ;
95
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V2_STORES ) ;
96
96
} ) ;
97
97
} ) ;
98
98
@@ -101,14 +101,21 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
101
101
expect ( db . version ) . to . equal ( 2 ) ;
102
102
// We should have all of the stores, we should have the target global row
103
103
// and we should not have any targets counted, because there are none.
104
- expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
104
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V2_STORES ) ;
105
105
// Check the target count. We haven't added any targets, so we expect 0.
106
106
return getTargetCount ( db ) . then ( targetCount => {
107
107
expect ( targetCount ) . to . equal ( 0 ) ;
108
108
} ) ;
109
109
} ) ;
110
110
} ) ;
111
111
112
+ it ( 'can install schema version 3' , ( ) => {
113
+ return withDb ( 3 , async db => {
114
+ expect ( db . version ) . to . be . equal ( 3 ) ;
115
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
116
+ } ) ;
117
+ } ) ;
118
+
112
119
it ( 'can upgrade from schema version 1 to 2' , ( ) => {
113
120
const expectedTargetCount = 5 ;
114
121
return withDb ( 1 , db => {
@@ -126,11 +133,20 @@ describe('IndexedDbSchema: createOrUpgradeDb', () => {
126
133
} ) . then ( ( ) =>
127
134
withDb ( 2 , db => {
128
135
expect ( db . version ) . to . equal ( 2 ) ;
129
- expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
136
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( V2_STORES ) ;
130
137
return getTargetCount ( db ) . then ( targetCount => {
131
138
expect ( targetCount ) . to . equal ( expectedTargetCount ) ;
132
139
} ) ;
133
140
} )
134
141
) ;
135
142
} ) ;
143
+
144
+ it ( 'can upgrade from schema version 2 to 3' , ( ) => {
145
+ return withDb ( 2 , async ( ) => { } ) . then ( ( ) =>
146
+ withDb ( 3 , async db => {
147
+ expect ( db . version ) . to . be . equal ( 3 ) ;
148
+ expect ( getAllObjectStores ( db ) ) . to . have . members ( ALL_STORES ) ;
149
+ } )
150
+ ) ;
151
+ } ) ;
136
152
} ) ;
0 commit comments