2018-09-17 15:53:23 +03:00
|
|
|
const {query} = require('graphqurl');
|
2019-01-15 14:40:29 +03:00
|
|
|
const fetch = require('node-fetch');
|
2018-09-17 15:53:23 +03:00
|
|
|
|
|
|
|
const complexQuery = `
|
|
|
|
query {
|
2019-01-15 14:40:29 +03:00
|
|
|
j2g_test_favoriteRoutes {
|
|
|
|
j2g_test_routesByJ2g_test_routesId {
|
|
|
|
j2g_test_leaguesByJ2g_test_leaguesId {
|
|
|
|
j2g_test_flightssByJ2g_test_leaguesId (
|
|
|
|
order_by: {
|
|
|
|
id:asc
|
|
|
|
}
|
|
|
|
){
|
|
|
|
j2g_test_flightCommentssByJ2g_test_flightsId(order_by: {j2g_test_users_id:asc}) {
|
|
|
|
j2g_test_users_id
|
|
|
|
j2g_test_usersByJ2g_test_usersId {
|
2018-09-17 15:53:23 +03:00
|
|
|
email
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`;
|
|
|
|
|
2019-01-15 14:40:29 +03:00
|
|
|
const testTables = [
|
|
|
|
'j2g_test_favoriteFlights',
|
|
|
|
'j2g_test_favoriteRoutes',
|
|
|
|
'j2g_test_files',
|
|
|
|
'j2g_test_flightComments',
|
|
|
|
'j2g_test_flightWaypoints',
|
|
|
|
'j2g_test_flights',
|
|
|
|
'j2g_test_leagueSeasonUserScores',
|
|
|
|
'j2g_test_leagues',
|
|
|
|
'j2g_test_mimetypes',
|
|
|
|
'j2g_test_noteTypes',
|
|
|
|
'j2g_test_routeWaypoints',
|
|
|
|
'j2g_test_routes',
|
|
|
|
'j2g_test_sponsors',
|
|
|
|
'j2g_test_types',
|
|
|
|
'j2g_test_userConfigs',
|
|
|
|
'j2g_test_userLeagues',
|
|
|
|
'j2g_test_userStatus',
|
|
|
|
'j2g_test_users',
|
|
|
|
'j2g_test_waypointChats',
|
|
|
|
'j2g_test_waypointNotes',
|
|
|
|
'j2g_test_waypointPhotos',
|
|
|
|
'j2g_test_waypointSuggestions',
|
|
|
|
'j2g_test_waypoints',
|
|
|
|
'j2g_test_wings',
|
|
|
|
];
|
|
|
|
|
|
|
|
const deleteTables = () => {
|
|
|
|
const deleteQuery = {
|
|
|
|
type: 'bulk',
|
|
|
|
args: testTables.map(tname => ({
|
|
|
|
type: 'run_sql',
|
|
|
|
args: {
|
|
|
|
sql: `drop table if exists public."${tname}" cascade;`,
|
|
|
|
cascade: true,
|
|
|
|
},
|
|
|
|
})),
|
|
|
|
};
|
|
|
|
fetch(
|
|
|
|
`${process.env.TEST_HGE_URL}/v1/query`,
|
|
|
|
{
|
|
|
|
method: 'POST',
|
2019-02-14 12:37:47 +03:00
|
|
|
headers: {'x-hasura-admin-secret': process.env.TEST_X_HASURA_ADMIN_SECRET},
|
2019-01-15 14:40:29 +03:00
|
|
|
body: JSON.stringify(deleteQuery),
|
|
|
|
}
|
|
|
|
).then(() => {
|
|
|
|
console.log('Test tables deleted!');
|
|
|
|
}).catch(() => console.log('Failed deleting test tables'));
|
|
|
|
};
|
|
|
|
|
2018-09-17 15:53:23 +03:00
|
|
|
const verifyDataImport = () => {
|
2019-01-15 14:40:29 +03:00
|
|
|
let resp = null;
|
|
|
|
return query({
|
2018-09-17 15:53:23 +03:00
|
|
|
query: complexQuery,
|
2019-05-10 09:05:11 +03:00
|
|
|
endpoint: `${process.env.TEST_HGE_URL}/v1/graphql`,
|
2019-02-14 12:37:47 +03:00
|
|
|
headers: {'x-hasura-admin-secret': process.env.TEST_X_HASURA_ADMIN_SECRET},
|
2018-09-17 15:53:23 +03:00
|
|
|
}).then(response => {
|
2019-01-15 14:40:29 +03:00
|
|
|
resp = response;
|
|
|
|
if (response.data.j2g_test_favoriteRoutes[0]
|
|
|
|
.j2g_test_routesByJ2g_test_routesId
|
|
|
|
.j2g_test_leaguesByJ2g_test_leaguesId
|
|
|
|
.j2g_test_flightssByJ2g_test_leaguesId[0]
|
|
|
|
.j2g_test_flightCommentssByJ2g_test_flightsId[0]
|
|
|
|
.j2g_test_usersByJ2g_test_usersId.email === 'osxcode@gmail.com') {
|
2018-09-17 15:53:23 +03:00
|
|
|
console.log('✔︎ Test passed');
|
|
|
|
} else {
|
|
|
|
console.log('✖ Test failed. Unexpected response.');
|
|
|
|
console.log(response.data);
|
|
|
|
}
|
2019-01-15 14:40:29 +03:00
|
|
|
}).catch(() => {
|
|
|
|
console.log('✖ Test failed. Unexpected response.');
|
|
|
|
console.log(JSON.stringify(resp, null, 2));
|
2018-09-17 15:53:23 +03:00
|
|
|
});
|
|
|
|
};
|
2019-01-15 14:40:29 +03:00
|
|
|
verifyDataImport().then(() => deleteTables()).catch(() => deleteTables());
|