1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00
squid-js/test/ocean/Order.test.ts

87 lines
2.5 KiB
TypeScript
Raw Normal View History

2018-10-10 11:02:00 +02:00
import * as assert from "assert"
2018-10-16 14:56:18 +02:00
import ConfigProvider from "../../src/ConfigProvider"
2018-10-10 11:02:00 +02:00
import ContractHandler from "../../src/keeper/ContractHandler"
2018-10-17 18:24:01 +02:00
import AccessStatus from "../../src/models/AccessStatus"
2018-10-10 11:02:00 +02:00
import Account from "../../src/ocean/Account"
import Asset from "../../src/ocean/Asset"
2018-10-16 14:56:18 +02:00
import Ocean from "../../src/ocean/Ocean"
2018-10-10 11:02:00 +02:00
import Order from "../../src/ocean/Order"
2018-10-16 14:56:18 +02:00
import config from "../config"
2018-10-10 11:02:00 +02:00
2018-10-17 18:24:01 +02:00
const testName = "Order Test Asset"
2018-10-16 14:56:18 +02:00
const testDescription = "This asset is pure owange"
const testPrice = 100
2018-10-17 18:24:01 +02:00
const timeout = 1000000
const accessToken = "eyJhbGciOiJIUzI1"
2018-10-10 11:02:00 +02:00
2018-10-16 14:56:18 +02:00
let ocean: Ocean
let testAsset: Asset
let accounts: Account[]
let testPublisher: Account
2018-10-17 18:24:01 +02:00
let testConsumer: Account
2018-10-10 11:02:00 +02:00
before(async () => {
2018-10-16 14:56:18 +02:00
ConfigProvider.configure(config)
await ContractHandler.deployContracts()
ocean = await Ocean.getInstance(config)
accounts = await ocean.getAccounts()
testPublisher = accounts[0]
2018-10-17 18:24:01 +02:00
testConsumer = accounts[1]
2018-10-16 14:56:18 +02:00
// register an asset to play around with
testAsset = new Asset(testName, testDescription, testPrice, testPublisher)
await ocean.register(testAsset)
2018-10-10 11:02:00 +02:00
})
describe("Order", () => {
2018-10-17 18:24:01 +02:00
describe("#pay()", async () => {
2018-10-10 11:02:00 +02:00
2018-10-17 18:24:01 +02:00
it("should pay for an order", async () => {
2018-10-10 11:02:00 +02:00
2018-10-17 18:24:01 +02:00
const order: Order = await testAsset.purchase(testConsumer, timeout)
2018-10-16 14:56:18 +02:00
assert(order)
2018-10-10 11:02:00 +02:00
2018-10-17 18:24:01 +02:00
await order.commit(accessToken)
await testConsumer.requestTokens(testAsset.price)
const paymentId: string = await order.pay(testConsumer)
assert(paymentId)
2018-10-10 11:02:00 +02:00
})
})
2018-10-16 14:56:18 +02:00
2018-10-17 18:24:01 +02:00
describe("#commit()", async () => {
it("should commit the order", async () => {
const order: Order = await testAsset.purchase(testConsumer, timeout)
assert(order)
await order.commit(accessToken)
})
})
describe("#getStatus()", async () => {
it("should get status Requested on new order", async () => {
const order: Order = await testAsset.purchase(testConsumer, timeout)
assert(order)
const status: AccessStatus = await order.getStatus()
assert(status === AccessStatus.Requested)
})
it("should get status Delivered on commited order", async () => {
const order: Order = await testAsset.purchase(testConsumer, timeout)
assert(order)
await order.commit(accessToken)
const status: AccessStatus = await order.getStatus()
assert(status === AccessStatus.Delivered)
})
})
2018-10-10 11:02:00 +02:00
})