1
1
import { IocContract } from '@adonisjs/fold'
2
2
import { initIocContainer } from '..'
3
- import { AppContext , AppServices } from '../app'
4
- import { Config } from '../config/app'
3
+ import { AppServices } from '../app'
4
+ import { Config , IAppConfig } from '../config/app'
5
5
import { createTestApp , TestContainer } from '../tests/app'
6
6
import { createAsset } from '../tests/asset'
7
7
import { createContext } from '../tests/context'
8
8
import { truncateTables } from '../tests/tableManager'
9
- import { AutoPeeringRoutes } from './routes'
9
+ import { AutoPeeringError , errorToCode , errorToMessage } from './errors'
10
+ import { AutoPeeringRoutes , PeerRequestContext } from './routes'
10
11
11
12
describe ( 'Auto Peering Routes' , ( ) : void => {
12
13
let deps : IocContract < AppServices >
13
14
let appContainer : TestContainer
14
15
let autoPeeringRoutes : AutoPeeringRoutes
16
+ let config : IAppConfig
15
17
16
18
beforeAll ( async ( ) : Promise < void > => {
17
19
deps = initIocContainer ( { ...Config , enableAutoPeering : true } )
18
20
appContainer = await createTestApp ( deps )
19
21
autoPeeringRoutes = await deps . use ( 'autoPeeringRoutes' )
22
+ config = await deps . use ( 'config' )
20
23
} )
21
24
22
25
afterEach ( async ( ) : Promise < void > => {
@@ -27,41 +30,56 @@ describe('Auto Peering Routes', (): void => {
27
30
await appContainer . shutdown ( )
28
31
} )
29
32
30
- describe ( 'get' , ( ) : void => {
31
- test ( 'returns peering details with assets' , async ( ) : Promise < void > => {
32
- const assets = await Promise . all ( [
33
- createAsset ( deps ) ,
34
- createAsset ( deps ) ,
35
- createAsset ( deps )
36
- ] )
33
+ describe ( 'acceptPeerRequest' , ( ) : void => {
34
+ test ( 'returns peering details' , async ( ) : Promise < void > => {
35
+ const asset = await createAsset ( deps )
37
36
38
- const ctx = createContext < AppContext > ( {
37
+ const ctx = createContext < PeerRequestContext > ( {
39
38
headers : { Accept : 'application/json' } ,
40
- url : `/`
39
+ url : `/` ,
40
+ body : {
41
+ staticIlpAddress : 'test.rafiki-money' ,
42
+ ilpConnectorAddress : 'http://peer.rafiki.money' ,
43
+ asset : { code : asset . code , scale : asset . scale } ,
44
+ httpToken : 'someHttpToken' ,
45
+ maxPacketAmount : 1000 ,
46
+ name : 'Rafiki Money'
47
+ }
41
48
} )
42
49
43
- await expect ( autoPeeringRoutes . get ( ctx ) ) . resolves . toBeUndefined ( )
50
+ await expect (
51
+ autoPeeringRoutes . acceptPeerRequest ( ctx )
52
+ ) . resolves . toBeUndefined ( )
53
+ expect ( ctx . status ) . toBe ( 200 )
44
54
expect ( ctx . body ) . toEqual ( {
45
- ilpAddress : Config . ilpAddress ,
46
- assets : expect . arrayContaining (
47
- assets . map ( ( asset ) => ( {
48
- code : asset . code ,
49
- scale : asset . scale
50
- } ) )
51
- )
55
+ staticIlpAddress : config . ilpAddress ,
56
+ ilpConnectorAddress : config . ilpConnectorAddress ,
57
+ httpToken : expect . any ( String ) ,
58
+ name : config . instanceName
52
59
} )
53
60
} )
54
61
55
- test ( 'returns peering details without assets ' , async ( ) : Promise < void > => {
56
- const ctx = createContext < AppContext > ( {
62
+ test ( 'properly handles error ' , async ( ) : Promise < void > => {
63
+ const ctx = createContext < PeerRequestContext > ( {
57
64
headers : { Accept : 'application/json' } ,
58
- url : `/`
65
+ url : `/` ,
66
+ body : {
67
+ staticIlpAddress : 'test.rafiki-money' ,
68
+ ilpConnectorAddress : 'http://peer.rafiki.money' ,
69
+ asset : { code : 'ABC' , scale : 2 } ,
70
+ httpToken : 'someHttpToken'
71
+ }
59
72
} )
60
73
61
- await expect ( autoPeeringRoutes . get ( ctx ) ) . resolves . toBeUndefined ( )
74
+ await expect (
75
+ autoPeeringRoutes . acceptPeerRequest ( ctx )
76
+ ) . resolves . toBeUndefined ( )
77
+ expect ( ctx . status ) . toBe ( errorToCode [ AutoPeeringError . UnknownAsset ] )
62
78
expect ( ctx . body ) . toEqual ( {
63
- ilpAddress : Config . ilpAddress ,
64
- assets : [ ]
79
+ error : {
80
+ code : errorToCode [ AutoPeeringError . UnknownAsset ] ,
81
+ message : errorToMessage [ AutoPeeringError . UnknownAsset ]
82
+ }
65
83
} )
66
84
} )
67
85
} )
0 commit comments