39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
#!/usr/bin/env node
|
|
'use strict';
|
|
|
|
const assert = require('assert');
|
|
const http = require('http');
|
|
const { createServer, resetState } = require('./server');
|
|
|
|
const port = Number(process.env.SMOKE_PORT || 4188);
|
|
function request(method, path, token, body) {
|
|
return new Promise((resolve, reject) => {
|
|
const payload = body === undefined ? undefined : JSON.stringify(body);
|
|
const req = http.request({ hostname: '127.0.0.1', port, path, method, headers: { Authorization: `Bearer ${token}`, ...(payload ? { 'Content-Type': 'application/json', 'Content-Length': Buffer.byteLength(payload) } : {}) } }, (res) => {
|
|
let raw = '';
|
|
res.on('data', (chunk) => { raw += chunk; });
|
|
res.on('end', () => resolve({ status: res.statusCode, body: JSON.parse(raw) }));
|
|
});
|
|
req.on('error', reject);
|
|
if (payload) req.write(payload);
|
|
req.end();
|
|
});
|
|
}
|
|
|
|
async function main() {
|
|
resetState();
|
|
const server = createServer().listen(port, '127.0.0.1');
|
|
try {
|
|
let response = await request('GET', '/app-api/education/context', 'tenant-a-student-1');
|
|
assert.equal(response.status, 200);
|
|
assert.equal(response.body.data.tenantId, 'tenant-a');
|
|
response = await request('GET', '/app-api/education/questions/page?collectionId=col-a-core', 'tenant-a-student-1');
|
|
assert.equal(response.body.data.list.length, 3);
|
|
assert.equal(response.body.data.list[0].answer, undefined);
|
|
process.stdout.write('education student harness smoke route passed\n');
|
|
} finally {
|
|
server.close();
|
|
}
|
|
}
|
|
main().catch((error) => { process.stderr.write(`${error.stack}\n`); process.exitCode = 1; });
|