Skip to content

Commit

Permalink
Add UserRepo mock in ExtraVars unit test
Browse files Browse the repository at this point in the history
Mock the UserRepo module to return a predefined apiKey for testing purposes. This ensures consistency and control over the test environment by avoiding external data dependencies.
  • Loading branch information
SquirrelDevelopper committed Nov 12, 2024
1 parent 27c34e7 commit ee08783
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/src/tests/unit-tests/modules/ansible/ExtraVars.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ vi.mock('../../../../data/database/repository/DeviceRepo', async () => {
};
});

vi.mock('../../../../data/database/repository/UserRepo', async () => {
const actual = await vi.importActual<any>('../../../../data/database/repository/UserRepo');
return {
default: {
...actual,
findFirst: async () => {
return { apiKey: 'test' };
},
},
};
});

describe('test ExtraVars', () => {
test('findValueOfExtraVars should return substituted variables', async () => {
const extraVars: API.ExtraVars = [
Expand Down

0 comments on commit ee08783

Please sign in to comment.