Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZinxValkyria committed May 31, 2024
1 parent 58adfc6 commit 7aacd20
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 26 deletions.
43 changes: 19 additions & 24 deletions __tests__/test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,32 @@ describe('GET /', () => {
const response = await request(app).get('/');
expect(response.status).toBe(200);
expect(response.text).toContain('Welcome to the MediaVerse Engine!');
});
},
describe('GET /movies', () => {
test('It should respond with status 200 and render movies page', async () => {
const response = await request(app).get('/movies');
expect(response.status).toBe(200);
expect(response.text).toContain('movies');
});
}),
});
});

// Add more tests for other routes...
describe('GET /movies', () => {
test('It should respond with status 200 and render movies page', async () => {
const response = await request(app).get('/movies');
expect(response.status).toBe(200);
expect(response.text).toContain('movies');
});
});

describe('GET /api/character', () => {
test('It should respond with character data', async () => {
const response = await request(app).get('/api/character?character=Iron%20Man'); // Use correct character name
const response = await request(app).get('/api/character?character=Iron Man');
expect(response.status).toBe(200);
expect(response.body).toHaveProperty('id');
expect(response.body).toHaveProperty('name', 'Iron Man');
// Add more assertions as needed...
});


test('It should handle errors gracefully', async () => {
// Mock the axios get method to simulate an error
jest.spyOn(require('axios'), 'get').mockRejectedValue(new Error('Axios error'));

const response = await request(app).get('/api/character?character=Spider-Man');
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error', 'Internal Server Error');
});
}))
});

// Add more tests for other API endpoints...
test('It should handle errors gracefully', async () => {
// Mock the axios get method to simulate an error
jest.spyOn(require('axios'), 'get').mockRejectedValue(new Error('Axios error'));

const response = await request(app).get('/api/character?character=Spider-Man');
expect(response.status).toBe(500);
expect(response.body).toHaveProperty('error', 'Internal Server Error');
});
});
1 change: 0 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ app.get('/api/character', async (req, res) => {
urls: characterData.urls
});
} catch (error) {
console.error('Error fetching character data:', error.message);
res.status(500).json({ error: 'Internal Server Error' });
}
});
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"start": "node app.js",
"test": "jest",
"test:mocha": "mocha",
"test:jest": "jest"
"test:jest": "jest --detectOpenHandles"
},
"author": "",
"license": "ISC",
Expand Down

0 comments on commit 7aacd20

Please sign in to comment.