Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(api): added health check for houses preview image #1406

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ typings
.DS_Store
app/.DS_Store

# ts generated for e2e
# ts generated for tests
results/
test-e2e/app/**/*.js
test-e2e/app/**/*.js.map
test-e2e/app/**/*.d.ts
test-api/test-data

#js Contentfull constants
!app/constants.js
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
"e2e:CI": "export API_URL=http://52.211.52.39:8015/v1 && ng e2e --no-webdriver-update --environment=qa --base-href /dollar-street --aot --prod",
"e2e:local": "API_URL=http://localhost:8015/v1 protractor ./.config/protractor.conf.js",
"e2e:local:consumer-dev": "API_URL=http://52.211.52.39:8015/v1 protractor ./.config/protractor.conf.js",
"e2e:dev": "API_URL=http://52.211.52.39:8015/v1 protractor --baseUrl='http://ds-dev.dollarstreet.org' ./.config/protractor.conf.js"
"e2e:dev": "API_URL=http://52.211.52.39:8015/v1 protractor --baseUrl='http://ds-dev.dollarstreet.org' ./.config/protractor.conf.js",
"api-test": "jasmine --config=test-api/jasmine.json --helper=test-api/{reporter,ts-node}.helper.js",
"preapi-test": "node ./test-api/get-list-of-houses.ts"
},
"pre-commit": [
"lint",
Expand Down Expand Up @@ -118,6 +120,7 @@
"protractor": "5.1.2",
"raw-loader": "0.5.1",
"reflect-metadata": "0.1.10",
"request-promise": "4.2.2",
"shelljs": "0.7.8",
"source-map-loader": "0.2.1",
"ts-loader": "2.1.0",
Expand Down
47 changes: 47 additions & 0 deletions test-api/get-list-of-houses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp');
const request = require('request-promise');
const getHousesList = 'https://consumer-api-prod.dollarstreet.org/v1/things?lang=en&thing=Families';

function generateJsonDirs() {
const jsonData = path.join(process.cwd(), 'test-api/test-data');
if (!fs.existsSync(jsonData)) {
mkdirp.sync(jsonData);
}
}

async function generateJsonFile() {
const recievedResponse = await request({
"method": "GET",
"uri": getHousesList,
"json": true,
"headers": {
"User-Agent": ""
}
});

const listOfHouses = await recievedResponse.data.streetPlaces.map((thing) => {
return thing._id;
});

fs.writeFile('./test-api/test-data/places.json', JSON.stringify(listOfHouses));
}

function rimraf(dir_path) {
if (fs.existsSync(dir_path)) {
fs.readdirSync(dir_path).forEach(entry => {
const entry_path = path.join(dir_path, entry);
if (fs.lstatSync(entry_path).isDirectory()) {
rimraf(entry_path);
} else {
fs.unlinkSync(entry_path);
}
});
fs.rmdirSync(dir_path);
}
}

rimraf(path.resolve(process.cwd(), './test-api/test-data'));
generateJsonDirs();
generateJsonFile();
8 changes: 8 additions & 0 deletions test-api/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"spec_dir": "",
"spec_files": [
"**/test.api-spec.ts"
],
"stopSpecOnExpectationFailure": false,
"random": false
}
22 changes: 22 additions & 0 deletions test-api/test.api-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const requestPromise = require('request-promise');
const sources = require('./test-data/places.json');

describe('Health-check for ', () => {
sources.forEach((data) => {
it(`house ${data}`, async () => {
const uri = `https://consumer-api-prod.dollarstreet.org/v1/matrix-view-block/?placeId=${data}&thingId=Families`;
const result = await requestPromise({
"method": "GET",
"uri": uri,
"json": true,
"headers": {}
});

const thingsArr = [result.data.houseImage, result.data.familyImage];
const brokenImages = thingsArr.filter(item => item === null);

expect(brokenImages.length).toBeLessThan(2);

}, 15000);
});
});
1 change: 1 addition & 0 deletions test-api/ts-node.helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('ts-node/dist').register({ project: 'test-e2e/tsconfig.json' });