-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdomainRoute.spec.ts
More file actions
145 lines (115 loc) · 5.13 KB
/
Copy pathdomainRoute.spec.ts
File metadata and controls
145 lines (115 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
The Licensed Work is (c) 2023 Sygma
SPDX-License-Identifier: LGPL-3.0-only
*/
import { expect } from "chai"
import axios from "axios"
import { Transfer, Resource, Fee, Deposit, Execution, Domain } from "@prisma/client"
type TransferResponse = Transfer & {
resource: Resource
toDomain: Domain
fromDomain: Domain
fee: Fee
deposit: Deposit
execution: Execution
}
const DOMAIN_1 = "1"
const DOMAIN_2 = "2"
const DOMAIN_3 = "3"
describe("Get all transfers with a specific domain as source or destination", function () {
before(async () => {
let transfers = 0
let isProcessing = false
while (transfers !== 35 || isProcessing) {
const res: { data: Array<TransferResponse> } = await axios.get("http://localhost:8000/api/transfers?page=1&limit=100")
transfers = res.data.length
isProcessing = false
for (const transfer of res.data) {
if (!transfer.deposit || !transfer.execution) {
isProcessing = true
}
}
}
})
it("Should successfully fetch all domain 1 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(35)
})
it("Should successfully fetch all transfers from domain 1", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(32)
for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
}
})
it("Should fail because the domain query parameter isn't source nor destination", async () => {
try {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}
/transfers?page=1&limit=100&domain=abc`)
expect(res.status).to.be.deep.equal(400)
} catch (e) {
expect(e).to.be.not.null
}
})
it("Should successfully fetch all transfers to domain 1", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_1}/transfers?page=1&limit=100&domain=destination`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)
for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_1))
}
})
it("Should successfully fetch all domain 2 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(30)
})
it("Should successfully fetch all transfers from domain 2", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(0)
for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_2))
}
})
it("Should successfully fetch all transfers to domain 2", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_2}/transfers?page=1&limit=100&domain=destination`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(30)
for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_2))
}
})
it("Should successfully fetch all domain 3 transfers", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(5)
})
it("Should successfully fetch all transfers from domain 3", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100&domain=source`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(3)
for (const transfer of transfers) {
expect(transfer.fromDomainId).to.be.deep.equal(parseInt(DOMAIN_3))
}
})
it("Should successfully fetch all transfers to domain 3", async () => {
const res = await axios.get(`http://localhost:8000/api/domains/${DOMAIN_3}/transfers?page=1&limit=100&domain=destination`)
const transfers = res.data as Array<TransferResponse>
expect(res.status).to.be.deep.equal(200)
expect(transfers.length).to.be.deep.equal(2)
for (const transfer of transfers) {
expect(transfer.toDomainId).to.be.deep.equal(parseInt(DOMAIN_3))
}
})
})