4
4
* See License.enterprise.txt in the project root folder.
5
5
*/
6
6
7
- import { Subscription } from ' @gitpod/gitpod-protocol/lib/accounting-protocol' ;
8
- import * as chai from ' chai' ;
9
- import { suite , test , timeout } from ' mocha-typescript' ;
10
- import { QueryRunner } from ' typeorm' ;
11
- import { AccountingDB } from ' ./accounting-db' ;
12
- import { oneMonthLater , rightAfter , rightBefore } from ' @gitpod/gitpod-protocol/lib/util/timeutil' ;
13
- import { DBAccountEntry } from ' ./typeorm/entity/db-account-entry' ;
14
- import { TransactionalAccountingDBImpl } from ' ./typeorm/accounting-db-impl' ;
15
- import { DBWorkspace } from ' ./typeorm/entity/db-workspace' ;
16
- import { DBWorkspaceInstance } from ' ./typeorm/entity/db-workspace-instance' ;
17
- import { DBSubscription } from ' ./typeorm/entity/db-subscription' ;
18
- import { testContainer } from ' ./test-container' ;
19
- import { TypeORM } from ' ./typeorm/typeorm' ;
7
+ import { Subscription } from " @gitpod/gitpod-protocol/lib/accounting-protocol" ;
8
+ import * as chai from " chai" ;
9
+ import { suite , test , timeout } from " mocha-typescript" ;
10
+ import { QueryRunner } from " typeorm" ;
11
+ import { AccountingDB } from " ./accounting-db" ;
12
+ import { oneMonthLater , rightAfter , rightBefore } from " @gitpod/gitpod-protocol/lib/util/timeutil" ;
13
+ import { DBAccountEntry } from " ./typeorm/entity/db-account-entry" ;
14
+ import { TransactionalAccountingDBImpl } from " ./typeorm/accounting-db-impl" ;
15
+ import { DBWorkspace } from " ./typeorm/entity/db-workspace" ;
16
+ import { DBWorkspaceInstance } from " ./typeorm/entity/db-workspace-instance" ;
17
+ import { DBSubscription } from " ./typeorm/entity/db-subscription" ;
18
+ import { testContainer } from " ./test-container" ;
19
+ import { TypeORM } from " ./typeorm/typeorm" ;
20
20
const expect = chai . expect ;
21
21
22
- @suite @timeout ( 5000 )
22
+ @suite
23
+ @timeout ( 5000 )
23
24
export class AccountingDBSpec {
24
-
25
25
typeORM = testContainer . get < TypeORM > ( TypeORM ) ;
26
26
db : AccountingDB ;
27
27
queryRunner : QueryRunner ;
@@ -37,7 +37,7 @@ export class AccountingDBSpec {
37
37
this . queryRunner = connection . createQueryRunner ( ) ;
38
38
await this . queryRunner . connect ( ) ;
39
39
await this . queryRunner . startTransaction ( ) ;
40
- this . db = new TransactionalAccountingDBImpl ( this . queryRunner . manager )
40
+ this . db = new TransactionalAccountingDBImpl ( this . queryRunner . manager ) ;
41
41
}
42
42
43
43
async after ( ) {
@@ -54,7 +54,7 @@ export class AccountingDBSpec {
54
54
startDate : now ,
55
55
endDate : later ,
56
56
amount : 1.01 ,
57
- planId : ' test'
57
+ planId : " test" ,
58
58
} ;
59
59
await this . db . newSubscription ( subscription ) ;
60
60
@@ -80,7 +80,7 @@ export class AccountingDBSpec {
80
80
startDate : now ,
81
81
endDate : undefined , // open ended
82
82
amount : 1.01 ,
83
- planId : ' test'
83
+ planId : " test" ,
84
84
} ;
85
85
await this . db . newSubscription ( subscription ) ;
86
86
@@ -104,43 +104,47 @@ export class AccountingDBSpec {
104
104
startDate : now ,
105
105
endDate : undefined , // open ended
106
106
amount : 1.01 ,
107
- planId : ' test'
107
+ planId : " test" ,
108
108
} ;
109
109
const dbSubscription = await this . db . newSubscription ( subscription ) ;
110
110
expectExactlyOne ( await this . db . findActiveSubscriptions ( now , rightAfter ( later ) ) , subscription ) ;
111
111
expect ( await this . db . findActiveSubscriptions ( rightBefore ( now ) , rightBefore ( now ) ) ) . to . be . empty ;
112
112
Subscription . cancelSubscription ( dbSubscription , later ) ;
113
- await this . db . storeSubscription ( dbSubscription )
113
+ await this . db . storeSubscription ( dbSubscription ) ;
114
114
expect ( await this . db . findActiveSubscriptions ( rightAfter ( later ) , rightAfter ( later ) ) ) . to . be . empty ;
115
- await this . db . storeSubscription ( dbSubscription )
115
+ await this . db . storeSubscription ( dbSubscription ) ;
116
116
expect ( await this . db . findActiveSubscriptions ( rightAfter ( later ) , rightAfter ( later ) ) ) . to . be . empty ;
117
117
}
118
118
119
119
@test public async subscriptionsForUser ( ) {
120
120
const now = new Date ( ) . toISOString ( ) ;
121
- const later = oneMonthLater ( now , 31 )
121
+ const later = oneMonthLater ( now , 31 ) ;
122
122
const subscription = < Subscription > {
123
123
userId : "Open ended" ,
124
124
startDate : now ,
125
125
endDate : undefined , // open ended
126
126
amount : 1.01 ,
127
- planId : ' test'
127
+ planId : " test" ,
128
128
} ;
129
129
let dbSubscription = await this . db . newSubscription ( subscription ) ;
130
130
expectExactlyOne ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , now ) , subscription ) ;
131
- expect ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , rightBefore ( now ) ) ) . to . be . an ( 'array' ) . and . empty ;
131
+ expect ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , rightBefore ( now ) ) ) . to . be . an ( "array" )
132
+ . and . empty ;
132
133
expectExactlyOne ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , later ) , subscription ) ;
133
134
Subscription . cancelSubscription ( dbSubscription , later ) ;
134
135
await this . db . storeSubscription ( dbSubscription ) ;
135
136
136
- expectExactlyOne ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , rightBefore ( later ) ) , dbSubscription ) ;
137
- expect ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , later ) ) . to . be . an ( 'array' ) . and . empty ;
137
+ expectExactlyOne (
138
+ await this . db . findActiveSubscriptionsForUser ( subscription . userId , rightBefore ( later ) ) ,
139
+ dbSubscription ,
140
+ ) ;
141
+ expect ( await this . db . findActiveSubscriptionsForUser ( subscription . userId , later ) ) . to . be . an ( "array" ) . and . empty ;
138
142
}
139
143
}
140
144
141
145
const expectExactlyOne = < T > ( result : T [ ] , expectation : T ) => {
142
146
expect ( result . length ) . to . be . equal ( 1 ) ;
143
147
expect ( result [ 0 ] ) . to . deep . include ( expectation ) ;
144
- }
148
+ } ;
145
149
146
- module . exports = new AccountingDBSpec
150
+ module . exports = new AccountingDBSpec ( ) ;
0 commit comments