diff options
| author | Emmanuel Gaillot <emmanuel.gaillot@gmail.com> | 2025-12-20 19:39:05 +0100 |
|---|---|---|
| committer | Emmanuel Gaillot <emmanuel.gaillot@gmail.com> | 2025-12-20 20:25:10 +0100 |
| commit | 487fd6802ef2cb248dbabd804fac2ae4c91e76e9 (patch) | |
| tree | 0fef7f3b0036313121b09435217b67e8995782f5 /lambda-calcul/javascript/test/client.test.js | |
| parent | c608d95a2451d110d3a90d6a3c3a6aa7fb293295 (diff) | |
| download | lambda-nantes-487fd6802ef2cb248dbabd804fac2ae4c91e76e9.tar.gz | |
Register user
Diffstat (limited to 'lambda-calcul/javascript/test/client.test.js')
| -rw-r--r-- | lambda-calcul/javascript/test/client.test.js | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lambda-calcul/javascript/test/client.test.js b/lambda-calcul/javascript/test/client.test.js new file mode 100644 index 0000000..8c4f98f --- /dev/null +++ b/lambda-calcul/javascript/test/client.test.js @@ -0,0 +1,41 @@ +const http = require('http'); +const LC = require('../src/client'); + +describe('λ-calculator', () => { + let challenger, port; + + beforeEach((done) => { + challenger = http.createServer(); + challenger.listen(0, () => { + port = challenger.address().port; + done(); + }); + }); + + afterEach((done) => { + challenger.close(() => done()); + }); + + it('registers to challenger', () => { + challenger.on('request', (request, response) => { + expect(request.method).toBe('POST'); + expect(request.url).toBe('/api/register'); + expect(request.headers).toHaveProperty('content-type', 'application/json;charset=utf-8'); + + let payload = ''; + request.on('data', (d) => (payload += d)); + request.on('end', () => { + expect(payload).toEqual('"John Smith"'); + }); + + response.end('SomeToken'); + }); + + const client = LC.newClient({ + playerName: 'John Smith', + challengerURL: `http://localhost:${port}`, + }); + return client.start() + .then((token) => expect(token).toBe('SomeToken')); + }); +}); |
