Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple Earn module #153

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions __tests__/spot/simpleEarn/getCollateralRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, expect */
const MissingParameterError = require('../../../src/error/missingParameterError')
const { nockMock, buildQueryString, SpotClient } = require('../../testUtils/testSetup')

const { mockResponse } = require('../../testUtils/mockData')

const productId = '1'

describe('#getCollateralRecord', () => {
describe('throw MissingParameterError', () => {
it('missing productId', () => {
expect(() => {
SpotClient.getCollateralRecord('')
}).toThrow(MissingParameterError)
})
})
it('should suscribe locked product', () => {
const parameters = {
productId
}
nockMock(`/sapi/v1/simple-earn/flexible/history/collateralRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getCollateralRecord(productId).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
28 changes: 28 additions & 0 deletions __tests__/spot/simpleEarn/getFlexiblePersonalLeftQuota.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, expect */
const MissingParameterError = require('../../../src/error/missingParameterError')
const { nockMock, buildQueryString, SpotClient } = require('../../testUtils/testSetup')

const { mockResponse } = require('../../testUtils/mockData')

const productId = '1'

describe('#getFlexiblePersonalLeftQuota', () => {
describe('throw MissingParameterError', () => {
it('missing productId', () => {
expect(() => {
SpotClient.getFlexiblePersonalLeftQuota('')
}).toThrow(MissingParameterError)
})
})
it('should redeem flexible product', () => {
const parameters = {
productId
}
nockMock(`/sapi/v1/simple-earn/flexible/personalLeftQuota?${buildQueryString({ ...parameters })}`)(mockResponse)

return SpotClient.getFlexiblePersonalLeftQuota(productId).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
28 changes: 28 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleProductList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getFlexibleProductList', () => {
it('should return flexible product list', () => {
nockMock('/sapi/v1/simple-earn/flexible/list')(mockResponse)

return SpotClient.getFlexibleProductList().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return flexible product list with params', () => {
const parameters = {
asset: 'USDT',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/flexible/list?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getFlexibleProductList(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleProductPosition.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getFlexibleProductPosition', () => {
it('should return flexible product position', () => {
nockMock('/sapi/v1/simple-earn/flexible/position')(mockResponse)

return SpotClient.getFlexibleProductPosition().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return flexible product position with params', () => {
const parameters = {
asset: 'USDT',
productId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/flexible/position?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getFlexibleProductPosition(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleRedemptionRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getFlexibleRedemptionRecord', () => {
it('should return flexible redemption records', () => {
nockMock('/sapi/v1/simple-earn/flexible/history/redemptionRecord')(mockResponse)

return SpotClient.getFlexibleRedemptionRecord().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return flexible redemption records with params', () => {
const parameters = {
asset: 'USDT',
productId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/flexible/history/redemptionRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getFlexibleRedemptionRecord(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
30 changes: 30 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleRewardsRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')
const MissingParameterError = require('../../../src/error/missingParameterError')

const type = 'FLEXIBLE'

describe('#getFlexibleRewardsRecord', () => {
describe('throw MissingParameterError', () => {
it('missing productId', () => {
expect(() => {
SpotClient.getFlexibleRewardsRecord('')
}).toThrow(MissingParameterError)
})
})

it('should return locked records history with params', () => {
const parameters = {
type,
productId: '1',
asset: 'USDT'
}
nockMock(`/sapi/v1/simple-earn/flexible/history/rewardsRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getFlexibleRewardsRecord(type, parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
36 changes: 36 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleSubscriptionPreview.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* global describe, it, expect */
const MissingParameterError = require('../../../src/error/missingParameterError')
const { nockMock, buildQueryString, SpotClient } = require('../../testUtils/testSetup')

const { mockResponse } = require('../../testUtils/mockData')

const productId = '1'
const amount = 10

describe('#getFlexibleSubscriptionPreview', () => {
describe('throw MissingParameterError', () => {
it('missing productId', () => {
expect(() => {
SpotClient.getFlexibleSubscriptionPreview('', amount)
}).toThrow(MissingParameterError)
})

it('missing amount', () => {
expect(() => {
SpotClient.getFlexibleSubscriptionPreview(productId, '')
}).toThrow(MissingParameterError)
})
})
it('should suscribe locked product', () => {
const parameters = {
productId,
amount
}
nockMock(`/sapi/v1/simple-earn/flexible/subscriptionPreview?${buildQueryString({ ...parameters })}`)(mockResponse)

return SpotClient.getFlexibleSubscriptionPreview(productId, amount).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getFlexibleSubscriptionRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getFlexibleSubscriptionRecord', () => {
it('should return flexible subscription records', () => {
nockMock('/sapi/v1/simple-earn/flexible/history/subscriptionRecord')(mockResponse)

return SpotClient.getFlexibleSubscriptionRecord().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return flexible subscription records with params', () => {
const parameters = {
asset: 'USDT',
purchaseId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/flexible/history/subscriptionRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getFlexibleSubscriptionRecord(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
28 changes: 28 additions & 0 deletions __tests__/spot/simpleEarn/getLockedPersonalLeftQuota.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, expect */
const MissingParameterError = require('../../../src/error/missingParameterError')
const { nockMock, buildQueryString, SpotClient } = require('../../testUtils/testSetup')

const { mockResponse } = require('../../testUtils/mockData')

const productId = '1'

describe('#getLockedPersonalLeftQuota', () => {
describe('throw MissingParameterError', () => {
it('missing productId', () => {
expect(() => {
SpotClient.getLockedPersonalLeftQuota('')
}).toThrow(MissingParameterError)
})
})
it('should redeem flexible product', () => {
const parameters = {
productId
}
nockMock(`/sapi/v1/simple-earn/locked/personalLeftQuota?${buildQueryString({ ...parameters })}`)(mockResponse)

return SpotClient.getLockedPersonalLeftQuota(productId).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
28 changes: 28 additions & 0 deletions __tests__/spot/simpleEarn/getLockedProductList.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getLockedProductList', () => {
it('should return locked product list', () => {
nockMock('/sapi/v1/simple-earn/locked/list')(mockResponse)

return SpotClient.getLockedProductList().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return locked product list with params', () => {
const parameters = {
asset: 'USDT',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/locked/list?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getLockedProductList(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getLockedProductPosition.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getLockedProductPosition', () => {
it('should return locked product position', () => {
nockMock('/sapi/v1/simple-earn/locked/position')(mockResponse)

return SpotClient.getLockedProductPosition().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return locked product position with params', () => {
const parameters = {
asset: 'USDT',
productId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/locked/position?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getLockedProductPosition(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getLockedRedemptionRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getLockedRedemptionRecord', () => {
it('should return locked redemption records', () => {
nockMock('/sapi/v1/simple-earn/locked/history/redemptionRecord')(mockResponse)

return SpotClient.getLockedRedemptionRecord().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return locked redemption records with params', () => {
const parameters = {
asset: 'USDT',
productId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/locked/history/redemptionRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getLockedRedemptionRecord(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
29 changes: 29 additions & 0 deletions __tests__/spot/simpleEarn/getLockedRewardsRecord.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* global describe, it, expect */
const { nockMock, SpotClient, buildQueryString } = require('../../testUtils/testSetup')
const { mockResponse } = require('../../testUtils/mockData')

describe('#getLockedRewardsRecord', () => {
it('should return locked records history', () => {
nockMock('/sapi/v1/simple-earn/locked/history/rewardsRecord')(mockResponse)

return SpotClient.getLockedRewardsRecord().then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})

it('should return locked records history with params', () => {
const parameters = {
asset: 'USDT',
positionId: '1',
current: 5,
size: 10
}
nockMock(`/sapi/v1/simple-earn/locked/history/rewardsRecord?${buildQueryString(parameters)}`)(mockResponse)

return SpotClient.getLockedRewardsRecord(parameters).then(response => {
expect(response).toBeDefined()
expect(response.data).toEqual(mockResponse)
})
})
})
Loading