Skip to content

Commit

Permalink
test: InfluxDBClient argument options
Browse files Browse the repository at this point in the history
  • Loading branch information
Sciator committed Aug 21, 2023
1 parent d8b3f92 commit 6552fc1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions packages/client/test/unit/Influxdb.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
import {expect} from 'chai'
import sinon from 'sinon'
import {InfluxDBClient, ClientOptions, Transport} from '../../src'
import type WriteApi from '../../src/WriteApi'
import type QueryApi from '../../src/QueryApi'
import {rejects} from 'assert'

describe('InfluxDB', () => {
afterEach(() => {
sinon.restore()
})

it('uses options database', () => {
const database = 'my-db'
const client = new InfluxDBClient({
host: 'http://localhost:8086',
database,
})
const writeApi: WriteApi = (client as any)._writeApi
const queryApi: QueryApi = (client as any)._queryApi
const writeStub = sinon.stub(writeApi, 'doWrite')
const queryStub = sinon.stub(queryApi, 'query')

const lines = ['lpdata']

client.write(lines)

expect(writeStub.calledWith(lines, database)).to.be.true
writeStub.resetHistory()

client.write(lines, 'another')
expect(writeStub.calledOnceWith(lines, 'another')).to.be.true

const query = 'select *'
client.query(query)

expect(queryStub.calledOnceWith(query, database, 'sql')).to.be.true
queryStub.resetHistory()

client.query(query, 'another')
expect(queryStub.calledOnceWith(query, 'another', 'sql')).to.be.true
})

it('throws when no database provided', async () => {
const client = new InfluxDBClient({
host: 'http://localhost:8086',
})

expect(() => client.query('query')).to.throw(`\
Please specify the 'database' as a method parameter or use default configuration \
at 'ClientOptions.database'
`)
await rejects(client.write('data'))
})

describe('constructor', () => {
it('is created from configuration with host', () => {
expect(
Expand Down

0 comments on commit 6552fc1

Please sign in to comment.