Skip to content

Commit

Permalink
'Database Started'
Browse files Browse the repository at this point in the history
  • Loading branch information
sschmitz1414 committed Mar 10, 2023
1 parent 7046acb commit 2505557
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 62 deletions.
32 changes: 11 additions & 21 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const pool = new Pool({
})

const query = async function (sql, params) {

let client
let results = []
try {
Expand All @@ -29,20 +28,20 @@ const query = async function (sql, params) {
return results
}

const queryAllCharacters = async function() {
const queryAllCharacters = async function () {
const sql = 'SELECT * FROM character;'

const results = await query(sql)

return {characters: results}
return { characters: results }
}

const queryAllComics = async function() {
const queryAllComics = async function () {
const sql = 'SELECT * FROM comic;'

const results = await query(sql)

return {comics: results}
return { comics: results }
}

express()
Expand All @@ -56,16 +55,9 @@ express()
})
.get('/health', async function (req, res) {
const characters = await queryAllCharacters()

if (characters != null) {
res.status(200).send('healthy')
} else {
res.status(500).send('query failed')
}

const comics = await queryAllComics()

if (comics != null) {
if (characters != null && comics != null) {
res.status(200).send('healthy')
} else {
res.status(500).send('query failed')
Expand All @@ -74,20 +66,18 @@ express()
.get('/about', function (req, res) {
res.render('pages/about')
})
.get('/getSQL', async function(req, res) {
.get('/getSQL', async function (req, res) {
const characterData = await queryAllCharacters()
res.render('pages/character', characterData)

const comicData = await queryAllComics()
res.render('pages/comic', comicData)
})


// end of implementation ///////////////////////////////////
.listen(PORT, () => console.log(`Listening on ${PORT}`))

module.exports = {
query,
queryAllCharacters,
queryAllComics
}
module.exports = {
query,
queryAllCharacters,
queryAllComics
}
80 changes: 39 additions & 41 deletions spec/support/CVSpec.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,55 @@
const {queryAllCharacters, queryAllComics} = require('../../server.js')
const { queryAllCharacters, queryAllComics } = require('../../server.js')

describe('server', function () {
const baseURL = 'http://localhost:5163'
const baseURL = 'http://localhost:5163'

const shouldBeAbove200 = async function (route) {
it('should be above 200', async function () {
const url = new URL(route, baseURL)
const shouldBeAbove200 = async function (route) {
it('should be above 200', async function () {
const url = new URL(route, baseURL)

const res = await fetch(url)
const res = await fetch(url)

expect(res.status).toBeGreaterThanOrEqual(200)
expect(res.status).toBeGreaterThanOrEqual(200)
}, 10000)
}

const shouldBeBelow399 = async function (route) {
it('should be below 399', async function () {
const url = new URL(route, baseURL)

}, 10000)
}
const res = await fetch(url)

const shouldBeBelow399 = async function (route) {
it('should be below 399', async function () {
const url = new URL(route, baseURL)
expect(res.status).toBeLessThanOrEqual(399)
}, 10000)
}

const res = await fetch(url)
describe("GET '/health'", function () {
shouldBeAbove200('/health')
})

expect(res.status).toBeLessThanOrEqual(399)
describe("GET '/health'", function () {
shouldBeBelow399('/health')
})

describe("GET '/'", function () {
shouldBeAbove200('/health')
})

}, 10000)
}
describe("GET '/'", function () {
shouldBeBelow399('/health')
})

const queryCheck = async function (route) {
it('check database queries', async function () {
expect(characterData).notEqual(null)

expect(comicData).notEqual(null)
})
}

describe("GET '/health'", function () {
shouldBeAbove200('/health')
})

describe("GET '/health'", function () {
shouldBeBelow399('/health')
})

describe("GET '/'", function () {
shouldBeAbove200('/health')
})

describe("GET '/'", function () {
shouldBeBelow399('/health')
describe('queryAllCharacters', function () {
it('should be defined', async function () {
const characterData = await queryAllCharacters()
expect(characterData).toBeDefined()
})
})

describe ("GET '/getSQL'", function () {
queryCheck('/getSQL')
describe('queryAllComics', function () {
it('should be defined', async function () {
const comicData = await queryAllComics()
expect(comicData).toBeDefined()
})
})
})
})

0 comments on commit 2505557

Please sign in to comment.