diff --git a/images/thumb/encenadaport.jpg b/images/thumb/encenadaport.jpg new file mode 100644 index 0000000..5466b21 Binary files /dev/null and b/images/thumb/encenadaport.jpg differ diff --git a/package.json b/package.json index f1f6b8a..888a4ec 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/support/jasmine.json b/spec/support/jasmine.json similarity index 100% rename from support/jasmine.json rename to spec/support/jasmine.json diff --git a/src/index.ts b/src/index.ts index 871b168..41bf9cf 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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; \ No newline at end of file diff --git a/src/routes/api/image.ts b/src/routes/api/image.ts index 760a01d..b2f5138 100644 --- a/src/routes/api/image.ts +++ b/src/routes/api/image.ts @@ -49,6 +49,9 @@ image.get('/', async (req: express.Request, res: express.Response): Promise { + 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); + }) + +}) + + + diff --git a/tsconfig.json b/tsconfig.json index 5db9a28..403acb7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }