Skip to content

Commit a8cb492

Browse files
committed
Add tests for usecase on get all environments
1 parent 1f5e014 commit a8cb492

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

test/api/environments.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,6 @@ module.exports = () => {
6666

6767
expect(response.status).to.equal(200);
6868
const environments = response.body.data;
69-
console.log('-------- Environments:');
70-
console.log(environments);
7169
expect(environments).to.lengthOf(8); // Assuming all environments were created in 2023
7270
expect(environments[0].id).to.equal('TDI59So3d');
7371
expect(environments[1].id).to.equal('EIDO13i3D');

test/lib/usecases/environment/GetAllEnvironmentsUseCase.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,33 @@ module.exports = () => {
161161
// Should include all environments with run numbers containing the substring 10
162162
expect(environments.map(({ id }) => id)).to.have.members(['TDI59So3d', 'Dxi029djX']);
163163
});
164+
165+
it('should successfully filter environments on created from and to', async () => {
166+
const from = Date.now() - 24 * 60 * 60 * 1000; // environment from 24h ago which was created by CreateEnvironmentUseCase.test.js
167+
const to = Date.now() - 10;
168+
getAllEnvsDto.query = { filter: { created: { from, to } } };
169+
const { environments } = await new GetAllEnvironmentsUseCase().execute(getAllEnvsDto);
170+
expect(environments).to.be.an('array');
171+
expect(environments.length).to.be.equal(2);
172+
expect(environments[0].id).to.be.equal('newId');
173+
expect(environments[1].id).to.be.equal('SomeId');
174+
});
175+
176+
it('should successfully filter environments on created from', async () => {
177+
const from = Date.now() - 24 * 60 * 60 * 1000; // environment from 24h ago which was created by CreateEnvironmentUseCase.test.js
178+
getAllEnvsDto.query = { filter: { created: { from } } };
179+
const { environments } = await new GetAllEnvironmentsUseCase().execute(getAllEnvsDto);
180+
expect(environments).to.be.an('array');
181+
expect(environments.length).to.be.equal(2);
182+
expect(environments[0].id).to.be.equal('newId');
183+
expect(environments[1].id).to.be.equal('SomeId');
184+
});
185+
186+
it('should successfully filter environments on created to', async () => {
187+
const to = Date.now() - 24 * 60 * 60 * 1000; // environment until 24h are created by seeders
188+
getAllEnvsDto.query = { filter: { created: { to } } };
189+
const { environments } = await new GetAllEnvironmentsUseCase().execute(getAllEnvsDto);
190+
expect(environments).to.be.an('array');
191+
expect(environments.length).to.be.equal(9); // Environments from seeders
192+
});
164193
};

0 commit comments

Comments
 (0)