added test with jasmine
This commit is contained in:
parent
3a0849efeb
commit
8929d7d41a
BIN
images/thumb/encenadaport.jpg
Normal file
BIN
images/thumb/encenadaport.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 30 KiB |
@ -24,6 +24,7 @@
|
||||
"@types/jasmine": "^3.10.3",
|
||||
"@types/node": "^17.0.9",
|
||||
"@types/sharp": "^0.29.5",
|
||||
"@types/supertest": "^2.0.11",
|
||||
"@typescript-eslint/eslint-plugin": "^5.10.1",
|
||||
"@typescript-eslint/parser": "^5.10.1",
|
||||
"eslint": "^8.7.0",
|
||||
@ -31,13 +32,14 @@
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"jasmine": "^4.0.2",
|
||||
"jasmine-spec-reporter": "^7.0.0",
|
||||
"nodemon": "^2.0.15",
|
||||
"ts-node": "^10.4.0",
|
||||
"typescript": "^4.5.4"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.17.2",
|
||||
"nodemon": "^2.0.15",
|
||||
"path": "^0.12.7",
|
||||
"sharp": "^0.29.3"
|
||||
"sharp": "^0.29.3",
|
||||
"supertest": "^6.2.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import express from 'express';
|
||||
import routes from './routes/routesIndex'
|
||||
import express from 'express'
|
||||
import routes from './routes/index'
|
||||
|
||||
const app = express();
|
||||
const port = 3000;
|
||||
@ -18,3 +18,4 @@ app.listen(port, () => {
|
||||
})
|
||||
|
||||
|
||||
export default app;
|
@ -49,6 +49,9 @@ image.get('/', async (req: express.Request, res: express.Response): Promise<void
|
||||
} else if (fileName) {
|
||||
// display original image if we only have filename parameter in the request
|
||||
res.sendFile(inputimgPath);
|
||||
} else {
|
||||
res.status(404).send("Something went wrong");
|
||||
return;
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -0,0 +1,42 @@
|
||||
import app from "../index"
|
||||
import image from "../routes/api/image"
|
||||
import supertest from "supertest"
|
||||
|
||||
const request = supertest(app);
|
||||
|
||||
// Endpoint testing
|
||||
describe('Test endpoint responses', () => {
|
||||
it('Get the api endpoint', async () => {
|
||||
const response = await request.get('/api/image?filename=fjord');
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
it('Throw an error if the image name is incorrect', async () => {
|
||||
const response = await request.get('/api/image?filename=test');
|
||||
expect(response.status).toBe(404);
|
||||
})
|
||||
it('Working if we only have a filename in the url', async () => {
|
||||
const response = await request.get('/api/image?filename=encenadaport');
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
})
|
||||
|
||||
// Image resize test
|
||||
|
||||
describe('Test of the image endpoint with resize', () => {
|
||||
it('Resize working with filename and width parameter', async () => {
|
||||
const response = await request.get('/api/image?filename=encenadaport&height=200');
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
it('Resize working with filename and height parameter', async () => {
|
||||
const response = await request.get('/api/image?filename=encenadaport&width=200');
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
it('Resize working with filename and width, height parameter', async () => {
|
||||
const response = await request.get('/api/image?filename=encenadaport&height=200');
|
||||
expect(response.status).toBe(200);
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
@ -98,5 +98,5 @@
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"exclude": ["node_modules", "build", "spec"]
|
||||
"exclude": ["node_modules", "build"]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user