Browse Source

Initial development of test

master
Smokeball Dev 5 years ago
parent
commit
cbce815e3d
6 changed files with 4084 additions and 0 deletions
  1. +0
    -0
      README.md
  2. +3990
    -0
      package-lock.json
  3. +14
    -0
      package.json
  4. +9
    -0
      src/get-urls.js
  5. +37
    -0
      src/get-urls.test.js
  6. +34
    -0
      src/mock-http-interface.js

+ 0
- 0
README.md View File


+ 3990
- 0
package-lock.json
File diff suppressed because it is too large
View File


+ 14
- 0
package.json View File

@ -0,0 +1,14 @@
{
"name": "@smokeball-dev/javascript-developer-test",
"version": "2.0.1",
"description": "",
"main": "./index.js",
"author": "Smokeball Development Team",
"license": "MIT",
"scripts": {
"test": "jest"
},
"dependencies": {
"jest": "25.1.0"
}
}

+ 9
- 0
src/get-urls.js View File

@ -0,0 +1,9 @@
const { getUrlP } = require('./mock-http-interface');
const getUrls = async (urls) => {
// TODO.
};
module.exports = {
getUrls,
};

+ 37
- 0
src/get-urls.test.js View File

@ -0,0 +1,37 @@
const { getUrls } = require('./get-urls');
const urls = [
'http://www.smokeballdev.com/url1',
'http://www.smokeballdev.com/url2',
'http://www.smokeballdev.com/url3',
'http://www.smokeballdev.com/url4',
];
test('expect no throws', () => {
expect.assertions(1);
expect(async () => results = await getUrls(urls)).not.toThrow();
});
test('responses to be correct', async () => {
expect.assertions(5);
const results = await getUrls(urls);
expect(results.length).toBe(4);
expect(results[0]).toEqual({ 'Arnie Quote': 'Get to the chopper' });
expect(results[1]).toEqual({ 'Arnie Quote': 'MY NAME IS NOT QUAID' });
expect(results[2]).toEqual({ 'Arnie Quote': `What's wrong with Wolfie?` });
expect(results[3]).toEqual({ 'FAILURE': 'Your request has been terminated' });
});
test('code to be executed in less than 400ms', async () => {
expect.assertions(2);
const startTime = process.hrtime();
await getUrls(urls);
const [ seconds, nanos ] = process.hrtime(startTime);
expect(seconds).toBe(0);
expect(nanos / 1000 / 1000).toBeLessThan(400);
});

+ 34
- 0
src/mock-http-interface.js View File

@ -0,0 +1,34 @@
'use strict';
const urlPrefix = `http://www.smokeballdev.com`;
const urlToResponseLookup = {
[`${urlPrefix}/url1`]: 'Get to the chopper',
[`${urlPrefix}/url2`]: 'MY NAME IS NOT QUAID',
[`${urlPrefix}/url3`]: `What's wrong with Wolfie?`,
};
const slowHttpRequestMockP = (url) => new Promise((resolve, reject) => {
setTimeout(() => {
const responseData = urlToResponseLookup[url];
if (responseData) {
resolve(responseData);
} else {
reject(new Error('Your request has been terminated'));
}
}, 200);
});
const getUrlP = async (url) => {
try {
const message = await slowHttpRequestMockP(url);
return { status: 200, body: JSON.stringify({ message }) };
}
catch (err) {
return { status: 500, body: JSON.stringify({ message: err.message }) };
}
};
module.exports = {
getUrlP,
};

Loading…
Cancel
Save