-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
372 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export function isTruthy(value: string): boolean { | ||
return value.toLowerCase() === 'true' || value === '1' || value === 'yes'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { PYTHON_API_URL } from './utils'; | ||
import * as fs from 'fs'; | ||
describe('python and Node api responses match', () => { | ||
const urls = JSON.parse( | ||
fs.readFileSync(`${__dirname}/utils/.urls.json`, 'utf8'), | ||
); | ||
|
||
it.each(urls)('%s', async ({ url, status }) => { | ||
let pythonResponse, nodeResponse, pythonResponseStatus, nodeResponseStatus; | ||
let pythonResponseBody, nodeResponseBody; | ||
let attempts = 0; | ||
while (attempts < 3) { | ||
try { | ||
pythonResponse = await fetch(`${PYTHON_API_URL}${url}`, { | ||
redirect: 'manual', | ||
}); | ||
nodeResponse = await fetch(`http://localhost:3000${url}`, { | ||
redirect: 'manual', | ||
}); | ||
if (pythonResponse?.status < 400 && nodeResponse?.status < 400) { | ||
pythonResponseStatus = pythonResponse?.status; | ||
nodeResponseStatus = nodeResponse?.status; | ||
pythonResponseBody = await pythonResponse?.text(); | ||
nodeResponseBody = await nodeResponse?.text(); | ||
break; | ||
} | ||
} catch (error) { | ||
console.error(`Attempt ${attempts + 1} failed:`, error); | ||
} | ||
attempts++; | ||
if (attempts < 3) { | ||
pythonResponseStatus = pythonResponse?.status; | ||
nodeResponseStatus = nodeResponse?.status; | ||
pythonResponseBody = await pythonResponse?.text(); | ||
nodeResponseBody = await nodeResponse?.text(); | ||
await new Promise((resolve) => setTimeout(resolve, 1000)); // Wait 1 second before retrying | ||
} | ||
} | ||
|
||
if (attempts === 3) { | ||
console.error(`Failed to fetch ${url} after 3 attempts`); | ||
} | ||
|
||
expect(pythonResponseStatus).toBe(status); | ||
expect(nodeResponseStatus).toBe(pythonResponseStatus); | ||
|
||
if (pythonResponseStatus === 200) { | ||
try { | ||
const pythonResponseJson = JSON.parse(pythonResponseBody); | ||
const nodeResponseJson = JSON.parse(nodeResponseBody); | ||
expect(nodeResponseJson).toEqual(pythonResponseJson); | ||
} catch { | ||
expect(nodeResponseBody).toEqual(pythonResponseBody); | ||
} | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
const PYTHON_API_PORT = 5031; | ||
export const PYTHON_API_URL = `http://localhost:${PYTHON_API_PORT}`; | ||
|
||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
Oops, something went wrong.