1
1
import assert from "assert" ;
2
+ import { config } from "../../src/config" ;
2
3
import axios from "axios" ;
3
4
import * as tokenUtils from "../../src/utils/tokenUtils" ;
4
5
import MockAdapter from "axios-mock-adapter" ;
5
6
import { validatelicenseKeyRegex } from "../../src/routes/verifyToken" ;
6
7
let mock : MockAdapter ;
7
8
8
9
const validateToken = validatelicenseKeyRegex ;
10
+ const fakePatreonIdentity = {
11
+ data : { } ,
12
+ links : { } ,
13
+ included : [
14
+ {
15
+ attributes : {
16
+ is_monthly : true ,
17
+ currently_entitled_amount_cents : 100 ,
18
+ patron_status : "active_patron" ,
19
+ } ,
20
+ id : "id" ,
21
+ type : "campaign"
22
+ }
23
+ ] ,
24
+ } ;
9
25
10
26
describe ( "tokenUtils test" , function ( ) {
11
27
before ( function ( ) {
12
28
mock = new MockAdapter ( axios , { onNoMatch : "throwException" } ) ;
13
- } ) ;
14
-
15
- it ( "Should be able to create patreon token" , ( done ) => {
16
29
mock . onPost ( "https://www.patreon.com/api/oauth2/token" ) . reply ( 200 , {
17
30
access_token : "test_access_token" ,
18
31
refresh_token : "test_refresh_token" ,
19
32
expires_in : 3600 ,
20
33
} ) ;
34
+ mock . onGet ( / i d e n t i t y / ) . reply ( 200 , fakePatreonIdentity ) ;
35
+ } ) ;
36
+
37
+ it ( "Should be able to create patreon token" , function ( done ) {
38
+ if ( ! config ?. patreon ) this . skip ( ) ;
21
39
tokenUtils . createAndSaveToken ( tokenUtils . TokenType . patreon , "test_code" ) . then ( ( licenseKey ) => {
22
40
assert . ok ( validateToken ( licenseKey ) ) ;
23
41
done ( ) ;
@@ -29,34 +47,15 @@ describe("tokenUtils test", function() {
29
47
done ( ) ;
30
48
} ) ;
31
49
} ) ;
32
- it ( "Should be able to get patreon identity" , ( done ) => {
33
- const fakePatreonIdentity = {
34
- data : { } ,
35
- links : { } ,
36
- included : [
37
- {
38
- attributes : {
39
- is_monthly : true ,
40
- currently_entitled_amount_cents : 100 ,
41
- patron_status : "active_patron" ,
42
- } ,
43
- id : "id" ,
44
- type : "campaign"
45
- }
46
- ] ,
47
- } ;
48
- mock . onGet ( / i d e n t i t y / ) . reply ( 200 , fakePatreonIdentity ) ;
50
+ it ( "Should be able to get patreon identity" , function ( done ) {
51
+ if ( ! config ?. patreon ) this . skip ( ) ;
49
52
tokenUtils . getPatreonIdentity ( "fake_access_token" ) . then ( ( result ) => {
50
53
assert . deepEqual ( result , fakePatreonIdentity ) ;
51
54
done ( ) ;
52
55
} ) ;
53
56
} ) ;
54
- it ( "Should be able to refresh token" , ( done ) => {
55
- mock . onPost ( "https://www.patreon.com/api/oauth2/token" ) . reply ( 200 , {
56
- access_token : "test_access_token" ,
57
- refresh_token : "test_refresh_token" ,
58
- expires_in : 3600 ,
59
- } ) ;
57
+ it ( "Should be able to refresh token" , function ( done ) {
58
+ if ( ! config ?. patreon ) this . skip ( ) ;
60
59
tokenUtils . refreshToken ( tokenUtils . TokenType . patreon , "fake-licence-Key" , "fake_refresh_token" ) . then ( ( result ) => {
61
60
assert . strictEqual ( result , true ) ;
62
61
done ( ) ;
0 commit comments