Skip to content
Merged
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
44 changes: 30 additions & 14 deletions tests/bottle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
async function getData() {
console.log("Running Bottle Test.");

const cruises = ["ar77", "en617", "hrs2303", "ae2426", "at46"];

const lineCounts = { ar77: 310, en617: 359, hrs2303: 145, ae2426: 266, at46: 305 };

async function getData(cruise) {
try {
const response = await fetch('http://localhost:8000/api/ctd/bottles/ar77');
const response = await fetch(`http://localhost:8000/api/ctd/bottles/${cruise}`);
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
}
Expand All @@ -12,22 +18,24 @@ async function getData() {
.map(line => line.trim())
.filter(line => line.length > 0);

if (lines.length == 310)
{
console.log('Bottles Get All test successful.');
const expected = lineCounts[cruise];

if (lines.length === expected)
{
console.log(`${cruise} Bottles Get All test successful.`);
}
else {
console.log('Bottles for All are missing.');
console.log('Bottles Get All test failed.');
console.log(`${cruise} Bottles for All are missing.`);
console.log(`${cruise} Bottles Get All test failed.`);
}
} catch (err) {
console.log('Bottles Get All test failed.');
console.log(`${cruise} Bottles Get All test failed.`);
console.error('Error:', err);
}


try {
const response = await fetch('http://localhost:8000/api/ctd/bottle_summary/ar77');
const response = await fetch(`http://localhost:8000/api/ctd/bottle_summary/${cruise}`);
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
}
Expand All @@ -38,16 +46,24 @@ async function getData() {
.map(line => line.trim())
.filter(line => line.length > 0);

if (lines.length == 310) {
console.log('Bottle Summary test successful.');
const expected = lineCounts[cruise];

if (lines.length === expected) {
console.log(`${cruise} Bottle Summary test successful.`);
} else {
console.log('Bottle Summary test failed.');
console.log(`${cruise} Bottle Summary test failed.`);
}

} catch (err) {
console.log('Bottle Summary test failed.');
console.log(`${cruise} Bottle Summary test failed.`);
console.error('Error:', err);
}
}

getData();
async function runAll() {
for (const cruise of cruises) {
await getData(cruise);
}
}

runAll();
114 changes: 66 additions & 48 deletions tests/cast.js
Original file line number Diff line number Diff line change
@@ -1,70 +1,81 @@
const fs = require('fs/promises');
const fs = require(`fs/promises`);
const path = require('path');
console.log("Running Cast Test.");

async function getData() {
const cruises = ["ar77", "en617", "hrs2303", "ae2426", "at46"];

const lineCounts = { ar77: 35, en617: 35, hrs2303: 12, ae2426: 20, at46: 23 };

async function getData(cruise) {
try {
const response = await fetch('http://localhost:8000/api/ctd/casts/get/ar77');
const response = await fetch(`http://localhost:8000/api/ctd/casts/get/${cruise}`);
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
throw new Error(`HTTP error ` + response.status);
}
const data = await response.json();

if (data.length == 35)
const expected = lineCounts[cruise];

if (data.length === expected)
{
console.log('Casts Get All test successful');
console.log(`${cruise} Casts Get All test successful.`);
}
else {
console.log('Casts for All are missing');
console.log('Casts Get All test failed');
console.log(`${cruise} Casts Get All are missing.`);
console.log(`${cruise} Casts Get All test failed.`);
}
} catch (err) {
console.log('Casts Get All test failed');
console.error('Error:', err);
console.log(`${cruise} Casts Get All test failed.`);
console.error(`Error:`, err);
}


try {
const response = await fetch('http://localhost:8000/api/ctd/cast/get/en608/10');
const response = await fetch(`http://localhost:8000/api/ctd/cast/get/${cruise}/10`);
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
if (cruise === 'ae2426') {
console.log(`${cruise} Cast Get Single test unsuccessful. This is the expected result for ae2426.`);
}
else {
throw new Error(`HTTP error ` + response.status);
}
}
const data = await response.text();

const lines = data
.split('\n')
.split(`\n`)
.map(line => line.trim())
.filter(line => line.length > 0); // Remove blank lines

if (lines.length > 1) {
console.log('Cast Get Single test successful');
} else {
console.log('Cast Get Single test failed');
}
if (lines.length > 1) {
console.log(`${cruise} Cast Get Single test successful.`);
} else {
console.log(`${cruise} Cast Get Single test failed.`);
}

} catch (err) {
console.log('Cast Get Single test failed');
console.error('Error:', err);
} catch (err) {
console.log(`${cruise} Cast Get Single test failed.`);
console.error(`Error:`, err);
}

var token;
const tokenPath = path.resolve(__dirname, 'token.txt');
if (path.basename(process.cwd()) === 'tests') {
token = (await fs.readFile("token.txt", 'utf-8')).trim();
const tokenPath = path.resolve(__dirname, `token.txt`);
if (path.basename(process.cwd()) === `tests`) {
token = (await fs.readFile("token.txt", `utf-8`)).trim();
}
else {
token = (await fs.readFile(tokenPath, 'utf-8')).trim();
token = (await fs.readFile(tokenPath, `utf-8`)).trim();
}

try {
const response = await fetch('http://localhost:8000/api/ctd/casts/create', {
const response = await fetch(`http://localhost:8000/api/ctd/casts/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
},
body: JSON.stringify({
"cruise_name": "ar77",
"cruise_name": `${cruise}`,
"number": "99",
"latitude": 40,
"longitude": -70,
Expand All @@ -78,23 +89,23 @@ async function getData() {

if (!response.ok) {
console.log(data.detail);
throw new Error('HTTP error ' + response.status);
throw new Error(`HTTP error ` + response.status);
}

if (data.status == 'success') {
console.log('Add Cast test successful.');
if (data.status === `success`) {
console.log(`${cruise} Add Cast 99 test successful.`);
} else {
console.log('Add Cast test failed.');
console.log(`${cruise} Add Cast 99 test failed.`);
}

}
catch (err) {
console.log('Add Cast test failed.');
console.error('Error:', err);
console.log(`${cruise} Add Cast 99 test failed.`);
console.error(`Error:`, err);
}

try {
const response = await fetch('http://localhost:8000/api/ctd/casts/update/ar77/99', {
const response = await fetch(`http://localhost:8000/api/ctd/casts/update/${cruise}/99`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -113,46 +124,53 @@ async function getData() {

if (!response.ok) {
console.log(data.detail);
throw new Error('HTTP error ' + response.status);
throw new Error(`HTTP error ` + response.status);
}

if (data.status == 'success') {
console.log('Modify Cast test successful.');
if (data.status === `success`) {
console.log(`${cruise} Modify Cast 99 test successful.`);
} else {
console.log('Modify Cast test failed.');
console.log(`${cruise} Modify Cast 99 test failed.`);
}

}
catch (err) {
console.log('Modify Cast test failed.');
console.error('Error:', err);
console.log(`${cruise} Modify Cast 99 test failed.`);
console.error(`Error:`, err);
}

try {
const response = await fetch('http://localhost:8000/api/ctd/casts/delete/ar77/99', {
const response = await fetch(`http://localhost:8000/api/ctd/casts/delete/${cruise}/99`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${token}`
}
});
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
throw new Error(`HTTP error ` + response.status);
}
const data = await response.json();

if (data.message == "Cast 99 on cruise ar77 deleted.") {
console.log('Delete Cast test successful.');
if (data.message === `Cast 99 on cruise ${cruise} deleted.`) {
console.log(`${cruise} Delete Cast 99 test successful.`);
} else {
console.log('Delete Cast test failed.');
console.log(`${cruise} Delete Cast 99 test failed.`);
}

}
catch (err) {
console.log('Delete Cast test failed.');
console.error('Error:', err);
console.log(`${cruise} Delete Cast 99 test failed.`);
console.error(`Error:`, err);
}

}

getData();

async function runAll() {
for (const cruise of cruises) {
await getData(cruise);
}
}

runAll();
50 changes: 29 additions & 21 deletions tests/chl.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
console.log("Running Chl Test.");

const cruises = ["ar77", "en617", "hrs2303", "ae2426", "at46"];

// Expected line counts - hrs2303 & ae2426 have no data
const lineCounts = { ar77: 315, en617: 339, hrs2303: 1, ae2426: 1, at46: 327 };

async function getData() {
try {
const response = await fetch('http://localhost:8000/api/chl/ar77');
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
}
for (const cruise of cruises) {
try {
const response = await fetch(`http://localhost:8000/api/chl/${cruise}`);
if (!response.ok) {
throw new Error('HTTP error ' + response.status);
}

const data = await response.text();
const data = await response.text();

const lines = data
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0);
const lines = data
.split('\n')
.map(line => line.trim())
.filter(line => line.length > 0);

if (lines.length == 315)
{
console.log('Chl Get test successful.');
}
else {
console.log('Chl values are missing.');
console.log('Chl Get test failed.');
const expected = lineCounts[cruise];

if (lines.length === expected) {
console.log(`${cruise} Chl Get test successful.`);
}
else {
console.log(`${cruise} Chl values are missing.`);
console.log(`${cruise} Chl Get test failed.`);
}
} catch (err) {
console.log(`${cruise} Chl Get test failed.`);
console.error('Error:', err);
}
}
} catch (err) {
console.log('Chl Get test failed.');
console.error('Error:', err);
}

try {
const response = await fetch('http://localhost:8000/api/chl/all');
Expand Down
Loading