Fix SambaPOS tests: switch SQL to mssql (named instance support), fix GraphQL token URL to use origin not full path

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
jtricerolph 2026-07-14 13:24:27 +00:00
parent f185b73678
commit e6470ad865
2 changed files with 17 additions and 13 deletions

View file

@ -7,6 +7,7 @@
"@fastify/cors": "^9.0.1", "@fastify/cors": "^9.0.1",
"fastify": "^4.28.1", "fastify": "^4.28.1",
"nodemailer": "^6.10.1", "nodemailer": "^6.10.1",
"mssql": "^11.0.1",
"pg": "^8.12.0" "pg": "^8.12.0"
} }
} }

View file

@ -141,25 +141,28 @@ export async function integrationRoutes(app) {
} }
else if (req.params.slug === 'sambapos') { else if (req.params.slug === 'sambapos') {
const errors = [] const errors = []
// SQL test // SQL test — SambaPOS uses MSSQL; host may be "server\INSTANCE"
try { try {
if (!creds.sql_host || !creds.sql_database || !creds.sql_username || !creds.sql_password) if (!creds.sql_host || !creds.sql_database || !creds.sql_username || !creds.sql_password)
throw new Error('SQL host, database, username and password are required') throw new Error('SQL host, database, username and password are required')
const { default: pg } = await import('pg') const { default: sql } = await import('mssql')
const sqlPool = new pg.Pool({ const [sqlServer, sqlInstance] = creds.sql_host.split('\\')
host: creds.sql_host, port: parseInt(creds.sql_port || '5432'), const cfg = {
database: creds.sql_database, user: creds.sql_username, password: creds.sql_password, server: sqlServer,
connectionTimeoutMillis: 8000, max: 1, database: creds.sql_database,
}) authentication: { type: 'default', options: { userName: creds.sql_username, password: creds.sql_password } },
await sqlPool.query('SELECT 1') options: { trustServerCertificate: true, connectTimeout: 8000, ...(sqlInstance ? { instanceName: sqlInstance } : { port: parseInt(creds.sql_port || '1433') }) },
await sqlPool.end() }
const pool = await sql.connect(cfg)
await pool.request().query('SELECT 1')
await pool.close()
} catch (e) { errors.push(`SQL: ${e.message}`) } } catch (e) { errors.push(`SQL: ${e.message}`) }
// GraphQL test — obtain token via password grant then run a minimal query // GraphQL test — token endpoint lives at origin, not inside /api path
try { try {
if (!creds.graphql_endpoint || !creds.graphql_username || !creds.graphql_password || !creds.graphql_client_id) if (!creds.graphql_endpoint || !creds.graphql_username || !creds.graphql_password || !creds.graphql_client_id)
throw new Error('GraphQL endpoint, username, password and client ID are required') throw new Error('GraphQL endpoint, username, password and client ID are required')
const base = creds.graphql_endpoint.replace(/\/$/, '') const origin = new URL(creds.graphql_endpoint).origin
const tokenRes = await fetch(`${base}/connect/token`, { const tokenRes = await fetch(`${origin}/connect/token`, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: new URLSearchParams({ body: new URLSearchParams({
@ -174,7 +177,7 @@ export async function integrationRoutes(app) {
if (!tokenRes.ok) throw new Error(`Token request failed (${tokenRes.status})`) if (!tokenRes.ok) throw new Error(`Token request failed (${tokenRes.status})`)
const { access_token } = await tokenRes.json() const { access_token } = await tokenRes.json()
if (!access_token) throw new Error('No access token returned') if (!access_token) throw new Error('No access token returned')
const gqlRes = await fetch(`${base}/api`, { const gqlRes = await fetch(creds.graphql_endpoint.replace(/\/$/, ''), {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${access_token}` }, headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${access_token}` },
body: JSON.stringify({ query: '{ __typename }' }), body: JSON.stringify({ query: '{ __typename }' }),