Skip to content

Commit

Permalink
Merge branch 'Development'
Browse files Browse the repository at this point in the history
  • Loading branch information
yunji0387 committed Apr 4, 2024
2 parents 18f8299 + bf26610 commit 3a8f6ff
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ This Node.js backend server is designed to manage football league standings, inc
- **PUT** `/standings/:code:` Update the standing by the competition code.
- **DELETE** `/standings/:code:` Delete the standing by the competition code.

### Mock API Endpoints
To conserve API request limits and avoid using real API calls to `api.football-data.org`, you can utilize mock data. These mock endpoints allow you to simulate operations without actual data modification or external API communication:
- **POST** `/mock/standings/:code:` Simulates the creation of a new standing using the specified competition code.
- **GET** `/mock/standings/:code:` Retrieves mock standing data for a given competition code.
- **PUT** `/mock/standings/:code:` Simulates the update of standings data for the specified competition code.
- **DELETE** `/mock/standings/:code:` Simulates the deletion of standings data for the specified competition code.


### Running Tests
Ensure you have a separate test database and set NODE_ENV to test to avoid using the production or development database. Run tests using:
```bash
Expand Down
58 changes: 58 additions & 0 deletions test/mockStanding.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// mockStandings.test.js
const supertest = require('supertest');
let chai;
before(async () => {
chai = await import('chai');
});

const app = require('../server'); // Adjust the path to your Express app
const request = supertest(app);

let expect;
before(async () => {
const chai = await import('chai');
expect = chai.expect;
});

describe('Mock Football League Standings Backend Server', () => {
const mockCompetitionCode = 'PL'; // Adjust based on your mock data
const invalidCompetitionCode = 'INVALID_CODE';

it('should retrieve a mock standing by competition code', async () => {
const response = await request.get(`/mock/standings/${mockCompetitionCode}`);
expect(response.status).to.equal(200);
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('data').that.is.an('object');
});

it('should simulate the creation of a new standing', async () => {
const response = await request.post(`/mock/standings/${mockCompetitionCode}`).send({ /* Mock payload */ });
expect(response.status).to.equal(201);
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('data').that.is.an('object');
});

it('should simulate updating a standing', async () => {
const response = await request.put(`/mock/standings/${mockCompetitionCode}`).send({ /* Mock update payload */ });
expect(response.status).to.equal(200);
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('message', 'Mock update successful');
});

it('should simulate deleting a standing by competition code', async () => {
const response = await request.delete(`/mock/standings/${mockCompetitionCode}`);
expect(response.status).to.equal(200);
expect(response.body).to.have.property('success', true);
expect(response.body).to.have.property('message', 'Standing successfully deleted');
});

it('should return a 404 for an invalid competition code on retrieval', async () => {
const response = await request.get(`/mock/standings/${invalidCompetitionCode}`);
expect(response.status).to.equal(404);
expect(response.body).to.have.property('success', false);
expect(response.body).to.have.property('message', 'Standing not found for the provided competition code');
});

// Additional tests for POST, PUT, and DELETE with invalidCompetitionCode similar to the above test
});

0 comments on commit 3a8f6ff

Please sign in to comment.