diff --git a/test-server/http.js b/test-server/http.js index 85e28a2..8d960f8 100644 --- a/test-server/http.js +++ b/test-server/http.js @@ -6,12 +6,24 @@ serve({ fetch(request) { console.log(`${request.method}: ${request.url}`); if (request.method === 'POST') { - const json = JSON.stringify(getBody()); + const url = new URL(request.url); + let json; + if (url.pathname === '/GetSVGLayoutConfiguration') { + json = JSON.stringify(GetSVGLayoutConfiguration()); + } else if (url.pathname === 'FillHoleWithChassis') { + json = JSON.stringify(FillHoleWithChassis(request)); + } else if (url.pathname === 'FillHoleWithChassis') { + json = JSON.stringify(SplitRemplissage(request)); + } else { + // TODO: Return 404 rather than this + json = JSON.stringify(GetSVGLayoutConfiguration()); + } return new Response(json, { status: 200, headers: { 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': '*' } }); } @@ -20,13 +32,14 @@ serve({ status: 200, headers: { 'Content-Type': 'text/plain', - 'Access-Control-Allow-Origin': '*' + 'Access-Control-Allow-Origin': '*', + 'Access-Control-Allow-Headers': '*' } }); } }); -const getBody = () => { +const GetSVGLayoutConfiguration = () => { return { AvailableContainers: [ { @@ -118,3 +131,38 @@ const getBody = () => { } }; }; + +const FillHoleWithChassis = (request) => { + const maxWidthChassis = 3000; + const nbChassis = Math.ceil(request.ContainerActions.Width / maxWidthChassis); + const lstModels = []; + for (let i = 0; i <= nbChassis; i++) { + if (i === 1 && request.ContainerAction.ExistOnBefore) { + lstModels.Add({ Type: 'Dilatation' }); + } + lstModels.Add({ Type: 'Chassis' }); + if (i < nbChassis) { + lstModels.Add({ Type: 'Dilatation' }); + } + if (i === nbChassis && request.ContainerAction.ExistOnAfter) { + lstModels.Add({ Type: 'Dilatation' }); + } + } + return { + ApplicationState: { + Containers: lstModels + } + }; +}; + +const SplitRemplissage = (request) => { + const lstModels = [ + { Type: 'Remplissage' }, + { Type: 'Montant' }, + { Type: 'Remplissage' } + ]; + + return { + ApplicationState: { Containers: lstModels } + }; +};