Skip to content

Commit

Permalink
update tests description
Browse files Browse the repository at this point in the history
  • Loading branch information
dutu committed Apr 25, 2023
1 parent 73e4380 commit 3240480
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 66 deletions.
56 changes: 26 additions & 30 deletions test/cjs/rest.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Poloniex = require('../../dist/cjs/poloniex.cjs')

const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms))

describe('REST tests', function () {
describe('REST tests - CJS', function () {
const expectGetCallRateInfoResult = (result) => {
expect(result).to.be.an('array').with.lengthOf(3)
expect(result[0]).to.be.a('string').and.to.be.oneOf(['riPub', 'nriPub', 'riPriv', 'nriPriv'])
Expand Down Expand Up @@ -397,11 +397,11 @@ describe('REST tests', function () {
describe('withdrawCurrency()', function () {
it('should return result', function (done) {
polo.withdrawCurrency({ currency: 'ETH' })
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('amount')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('amount')
done()
})
})

it('should return api calls info', function () {
Expand Down Expand Up @@ -457,11 +457,11 @@ describe('REST tests', function () {

it('should return result', function (done) {
polo.createOrder(order)
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('balance')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('balance')
done()
})
})

it('should return api calls info', function () {
Expand All @@ -473,11 +473,11 @@ describe('REST tests', function () {
describe('createBatchOrders()', function () {
const orders = [
{
symbol: 'BTC_USDT',
side: 'SELL',
type: 'LIMIT',
price: '60000',
quantity: '100',
symbol: 'BTC_USDT',
side: 'SELL',
type: 'LIMIT',
price: '60000',
quantity: '100',
},
{
symbol: 'BTC_USDT',
Expand All @@ -488,13 +488,13 @@ describe('REST tests', function () {
}
]

it('should return result', function (done) {
it('should return result', function (done) {
polo.createBatchOrders({ orders })
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('Parameter')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('Parameter')
done()
})
})

it('should return api calls info', function () {
Expand All @@ -506,21 +506,17 @@ describe('REST tests', function () {
describe('replaceOrder()', function () {
it('should return result', function (done) {
polo.replaceOrder({ id: '00000' })
.catch((err) => {
expect(err).to.be.an('Error')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
done()
})
})

it('should return api calls info', function () {
let result = polo.createBatchOrders({ id: '00000', getApiCallRateInfo: true })
expectGetCallRateInfoResult(result)
})
})




})

describe('API call rate info', function() {
Expand Down
2 changes: 1 addition & 1 deletion test/cjs/webSocket.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Poloniex = require('../../dist/cjs/poloniex.cjs')

const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms))

describe('WebSocket tests', function () {
describe('WebSocket tests - CJS', function () {
describe('Public WebSocket', function () {
let ws

Expand Down
52 changes: 26 additions & 26 deletions test/esm/rest.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const expect = chai.expect

const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms))

describe('REST tests', function () {
describe('REST tests - ESM', function () {
const expectGetCallRateInfoResult = (result) => {
expect(result).to.be.an('array').with.lengthOf(3)
expect(result[0]).to.be.a('string').and.to.be.oneOf(['riPub', 'nriPub', 'riPriv', 'nriPriv'])
Expand Down Expand Up @@ -398,11 +398,11 @@ describe('REST tests', function () {
describe('withdrawCurrency()', function () {
it('should return result', function (done) {
polo.withdrawCurrency({ currency: 'ETH' })
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('amount')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('amount')
done()
})
})

it('should return api calls info', function () {
Expand Down Expand Up @@ -458,11 +458,11 @@ describe('REST tests', function () {

it('should return result', function (done) {
polo.createOrder(order)
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('balance')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('balance')
done()
})
})

it('should return api calls info', function () {
Expand All @@ -474,11 +474,11 @@ describe('REST tests', function () {
describe('createBatchOrders()', function () {
const orders = [
{
symbol: 'BTC_USDT',
side: 'SELL',
type: 'LIMIT',
price: '60000',
quantity: '100',
symbol: 'BTC_USDT',
side: 'SELL',
type: 'LIMIT',
price: '60000',
quantity: '100',
},
{
symbol: 'BTC_USDT',
Expand All @@ -489,13 +489,13 @@ describe('REST tests', function () {
}
]

it('should return result', function (done) {
it('should return result', function (done) {
polo.createBatchOrders({ orders })
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('Parameter')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
expect(err.message).to.include('Parameter')
done()
})
})

it('should return api calls info', function () {
Expand All @@ -507,10 +507,10 @@ describe('REST tests', function () {
describe('replaceOrder()', function () {
it('should return result', function (done) {
polo.replaceOrder({ id: '00000' })
.catch((err) => {
expect(err).to.be.an('Error')
done()
})
.catch((err) => {
expect(err).to.be.an('Error')
done()
})
})

it('should return api calls info', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/esm/webSocket.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const expect = chai.expect

const delay = (ms) => new Promise((resolve) => setTimeout(() => resolve(), ms))

describe('WebSocket tests', function () {
describe('WebSocket tests - ESM', function () {
describe('Public WebSocket', function () {
let ws

Expand Down
31 changes: 23 additions & 8 deletions test/package.test.cjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
const { expect } = require('chai');
const packageJSON = require('../package.json');
const { expect } = require('chai')
const { join } = require('path');
const packageJSON = require('../package.json')

describe('package.json', () => {
it('should have the correct "main" entry for CommonJS', () => {
expect(packageJSON.main).to.equal('./dist/cjs/poloniex.cjs');
});
it('should have the correct "exports" entry for ESM', async () => {
const modulePath = packageJSON.exports['.'].import
const filePath = join(process.cwd(), modulePath);
const importedModule = await import(filePath)
expect(importedModule.default).to.be.a('function')
})

it('should have the correct "module" entry for ESM', async () => {
expect(packageJSON.module).to.equal(packageJSON.exports['.'].import)
})

it('should have the correct "module" entry for ESM', () => {
expect(packageJSON.module).to.equal('./lib/poloniex.mjs');
it('should have the correct "exports" entry for CommonJS', () => {
const modulePath = packageJSON.exports['.'].require
const filePath = join(process.cwd(), modulePath)
const requiredModule = require(filePath)
expect(requiredModule).to.be.an('function')
});
});

it('should have the correct "main" entry for CommonJS', () => {
expect(packageJSON.main).to.equal(packageJSON.exports['.'].require)
})
})

0 comments on commit 3240480

Please sign in to comment.