Skip to content

Commit

Permalink
Use stub sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles committed Nov 22, 2024
1 parent 8c489f0 commit 53e85fa
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions server/test/services/free-mobile/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ describe('FreeMobileService', () => {
let axiosStub;
let gladys;
let freeMobileService;
let sandbox;

beforeEach(() => {
sandbox = sinon.createSandbox();
axiosStub = {
get: async () => {
return { data: 'OK' };
Expand Down Expand Up @@ -41,6 +43,10 @@ describe('FreeMobileService', () => {
freeMobileService = FreeMobileService(gladys, serviceId);
});

afterEach(() => {
sandbox.restore();
});

describe('start', () => {
it('should start service with success', async () => {
await freeMobileService.start();
Expand All @@ -50,7 +56,6 @@ describe('FreeMobileService', () => {
});

it('should throw ServiceNotConfiguredError if username is missing', async () => {
// gladys.variable.getValue.resolves(null);
gladys.variable.getValue = async (key) => {
if (key === 'FREE_MOBILE_USERNAME') {
return null;
Expand All @@ -70,13 +75,6 @@ describe('FreeMobileService', () => {
});

it('should throw ServiceNotConfiguredError if accessToken is missing', async () => {
/*
gladys.variable.getValue
.onFirstCall()
.resolves('validUsername')
.onSecondCall()
.resolves(null);
*/
gladys.variable.getValue = async (key) => {
if (key === 'FREE_MOBILE_USERNAME') {
return 'validUsername';
Expand Down Expand Up @@ -119,7 +117,7 @@ describe('FreeMobileService', () => {
axiosStub.get = async () => {
throw new Error('Network error');
};
const loggerErrorStub = sinon.stub(logger, 'error');
const loggerErrorStub = sandbox.stub(logger, 'error');
await freeMobileService.sms.send('Hello World');
const errorArgs = loggerErrorStub.getCall(0).args;
expect(errorArgs[0]).to.equal('Error sending SMS:');
Expand Down

0 comments on commit 53e85fa

Please sign in to comment.