import test from 'brittle'
import { PghClient } from '../lib/client.js'
test('PghClient — constructs with defaults', (t) => {
const client = new PghClient()
t.is(client.server, 'http://localhost:5005')
t.is(client.token, null)
})
test('PghClient — custom server and token', (t) => {
const client = new PghClient({ server: 'http://example.com:9000', token: 'abc123' })
t.is(client.server, 'http://example.com:9000')
t.is(client.token, 'abc123')
})
test('PghClient — _headers includes Bearer when token set', (t) => {
const client = new PghClient({ token: 'mytoken' })
const h = client._headers()
t.is(h.Authorization, 'Bearer mytoken')
t.is(h.Accept, 'application/json')
})
test('PghClient — _headers omits Authorization when no token', (t) => {
const client = new PghClient()
const h = client._headers()
t.absent(h.Authorization)
t.is(h.Accept, 'application/json')
})
test('PghClient — convenience methods return correct paths', (t) => {
// Verify the URL construction by checking the method exists
const client = new PghClient()
t.is(typeof client.status, 'function')
t.is(typeof client.repos, 'function')
t.is(typeof client.repo, 'function')
t.is(typeof client.issues, 'function')
t.is(typeof client.createIssue, 'function')
t.is(typeof client.updateIssue, 'function')
t.is(typeof client.addComment, 'function')
t.is(typeof client.deploy, 'function')
t.is(typeof client.deployConfig, 'function')
t.is(typeof client.deployLog, 'function')
t.is(typeof client.search, 'function')
t.is(typeof client.adminStats, 'function')
t.is(typeof client.adminUsers, 'function')
t.is(typeof client.adminTokens, 'function')
})