-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathe2e.test.js
40 lines (34 loc) · 1.29 KB
/
e2e.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import assert from 'node:assert';
import process from 'node:process';
import { Guard, Validators, exit } from './dist/index.js';
process.on('exit', (code) => {
console.log(`About to exit with code: ${code}`);
exit();
});
async function main () {
try {
const guard = await Guard.fromString(
[await Validators.ValidLength(1, 10, 'reask')],
{
description: 'A word.',
prompt: 'Generate a single word with a length betwen 1 and 10.'
}
);
const firstResponse = await guard.parse('Hello World!', { fullSchemaReask: true });
console.log("first response: ", JSON.stringify(firstResponse, null, 2));
assert.equal(firstResponse.validationPassed, true);
assert.equal(firstResponse.validatedOutput, 'Hello Worl');
assert.equal(guard.history.at(0).status, 'pass');
const secondResponse = await guard.parse('Hello World 2!');
console.log("second response: ", JSON.stringify(secondResponse, null, 2));
assert.equal(secondResponse.validationPassed, true);
assert.equal(secondResponse.validatedOutput, 'Hello Worl');
assert.equal(guard.history.at(1).status, 'pass');
console.log('Reask prompt: ', guard.history.at(1).reask_prompts);
process.exit(0);
} catch (error) {
console.error(error);
process.exit(1);
}
}
await main();