summaryrefslogtreecommitdiff
path: root/lambda-calcul/javascript
diff options
context:
space:
mode:
authorEmmanuel Gaillot <emmanuel.gaillot@gmail.com>2025-12-20 20:26:00 +0100
committerEmmanuel Gaillot <emmanuel.gaillot@gmail.com>2025-12-20 22:00:26 +0100
commit800f5628d86313c315d38e983318bb0a027137e2 (patch)
treef5637077f0782fb9c8c1b15fb16274f4b5ee03fb /lambda-calcul/javascript
parent487fd6802ef2cb248dbabd804fac2ae4c91e76e9 (diff)
downloadlambda-nantes-800f5628d86313c315d38e983318bb0a027137e2.tar.gz
Retrieve next challenge
Diffstat (limited to 'lambda-calcul/javascript')
-rw-r--r--lambda-calcul/javascript/index.js4
-rw-r--r--lambda-calcul/javascript/src/client.js6
-rw-r--r--lambda-calcul/javascript/test/client.test.js16
3 files changed, 25 insertions, 1 deletions
diff --git a/lambda-calcul/javascript/index.js b/lambda-calcul/javascript/index.js
index 03bcaf6..e06ac4d 100644
--- a/lambda-calcul/javascript/index.js
+++ b/lambda-calcul/javascript/index.js
@@ -8,4 +8,6 @@ client = LC.newClient({
});
client.start()
- .then((token) => console.log(`${playerName} has registered with token ${token}`));
+ .then((token) => console.log(`${playerName} has registered with token ${token}`) || token)
+ .then(client.nextChallenge)
+ .then((challenge) => console.log(`Next challenge: ${challenge}`));
diff --git a/lambda-calcul/javascript/src/client.js b/lambda-calcul/javascript/src/client.js
index d2de0d4..d046187 100644
--- a/lambda-calcul/javascript/src/client.js
+++ b/lambda-calcul/javascript/src/client.js
@@ -1,6 +1,11 @@
const axios = require('axios');
const newClient = ({ playerName, challengerURL }) => {
+ const nextChallenge = (token) => axios ({
+ url: `${challengerURL}/api/challenge?token=${token}`,
+ })
+ .then(({ data: { expr } }) => expr);
+
const start = () => axios({
method: 'POST',
url: `${challengerURL}/api/register`,
@@ -10,6 +15,7 @@ const newClient = ({ playerName, challengerURL }) => {
.then(({ data }) => data);
return {
+ nextChallenge,
start,
};
};
diff --git a/lambda-calcul/javascript/test/client.test.js b/lambda-calcul/javascript/test/client.test.js
index 8c4f98f..5fcc42c 100644
--- a/lambda-calcul/javascript/test/client.test.js
+++ b/lambda-calcul/javascript/test/client.test.js
@@ -38,4 +38,20 @@ describe('λ-calculator', () => {
return client.start()
.then((token) => expect(token).toBe('SomeToken'));
});
+
+ it('retrieves next challenge', () => {
+
+ challenger.on('request', (request, response) => {
+ expect(request.method).toBe('GET');
+ expect(request.url).toBe('/api/challenge?token=SomeToken');
+ response.end(JSON.stringify({ expr: 'SomeChallenge' }));
+ });
+
+ const client = LC.newClient({
+ playerName: 'John Smith',
+ challengerURL: `http://localhost:${port}`,
+ });
+ return client.nextChallenge('SomeToken')
+ .then((challenge) => expect(challenge).toBe('SomeChallenge'));
+ });
});