1
+ import assert from "assert" ;
2
+ import vscode from "vscode" ;
3
+ import { TestSuite } from "." ;
4
+ import { instance } from "../instantiate" ;
5
+
6
+ export const StorageSuite : TestSuite = {
7
+ name : `Extension storage tests` ,
8
+ tests : [
9
+ {
10
+ name : "Authorized extensions" , test : async ( ) => {
11
+ const storage = instance . getStorage ( ) ;
12
+ if ( storage ) {
13
+ const extension = vscode . extensions . getExtension ( "halcyontechltd.code-for-ibmi" ) ! ;
14
+ try {
15
+ let auth = storage . getExtensionAuthorisation ( extension ) ;
16
+ assert . strictEqual ( undefined , auth , "Extension is already authorized" ) ;
17
+ storage . grantExtensionAuthorisation ( extension ) ;
18
+
19
+ auth = storage . getExtensionAuthorisation ( extension ) ;
20
+ assert . ok ( auth , "Authorisation not found" ) ;
21
+ assert . strictEqual ( new Date ( auth . since ) . toDateString ( ) , new Date ( ) . toDateString ( ) , "Access date must be today" ) ;
22
+
23
+ const lastAccess = auth . lastAccess ;
24
+ await new Promise ( r => setTimeout ( r , 100 ) ) ; //Wait a bit
25
+ auth = storage . getExtensionAuthorisation ( extension ) ;
26
+ assert . ok ( auth , "Authorisation not found" ) ;
27
+ assert . notStrictEqual ( lastAccess , auth . lastAccess , "Last access did not change" )
28
+ }
29
+ finally {
30
+ const auth = storage . getExtensionAuthorisation ( extension ) ;
31
+ if ( auth ) {
32
+ storage . revokeExtensionAuthorisation ( auth ) ;
33
+ }
34
+ }
35
+ }
36
+ else {
37
+ throw Error ( "Cannot run test: no storage" )
38
+ }
39
+ }
40
+ }
41
+ ]
42
+ }
0 commit comments