summaryrefslogtreecommitdiff
path: root/lambda-calcul/javascript/test/client.test.js
diff options
context:
space:
mode:
authorEmmanuel Gaillot <emmanuel.gaillot@gmail.com>2025-12-20 22:27:27 +0100
committerEmmanuel Gaillot <emmanuel.gaillot@gmail.com>2025-12-20 22:27:27 +0100
commit2ac732dc527d53974d65a5afbb33c452a567797b (patch)
treebe422f4d47652dd92552302c9bcb5bd954839cf5 /lambda-calcul/javascript/test/client.test.js
parent1b1877e3328170fe839d2f8ca4d108ec2b0a0454 (diff)
downloadlambda-nantes-2ac732dc527d53974d65a5afbb33c452a567797b.tar.gz
Post solution
Diffstat (limited to 'lambda-calcul/javascript/test/client.test.js')
-rw-r--r--lambda-calcul/javascript/test/client.test.js26
1 files changed, 26 insertions, 0 deletions
diff --git a/lambda-calcul/javascript/test/client.test.js b/lambda-calcul/javascript/test/client.test.js
index 8a5ebff..a001c6f 100644
--- a/lambda-calcul/javascript/test/client.test.js
+++ b/lambda-calcul/javascript/test/client.test.js
@@ -80,6 +80,32 @@ describe('λ-calculator', () => {
expect(client.solve('Some challenge')).toBe('Expression to print');
});
+ it('posts solution', () => {
+ let challengerCalled = false;
+
+ challenger.on('request', (request, response) => {
+ challengerCalled = true;
+ expect(request.headers).toHaveProperty('content-type', 'application/json;charset=utf-8');
+ expect(request.method).toBe('POST');
+ expect(request.url).toBe('/api/challenge?token=SomeToken');
+
+ let payload = '';
+ request.on('data', (d) => (payload += d));
+ request.on('end', () => {
+ expect(payload).toEqual('"answer"');
+ });
+
+ response.end();
+ });
+
+ const client = LC.newClient({
+ playerName: 'John Smith',
+ challengerURL: `http://localhost:${port}`,
+ });
+ return client.postSolution('SomeToken', "answer")
+ .then(() => expect(challengerCalled).toBe(true));
+ });
+
it('unregisters user', () => {
let challengerCalled = false;