afterEach(() => { sandbox.restore() })
it('should update password and send confirmation email when email and reset token are valid', async () => { await PasswordResetToken.create(resetToken); sandbox .stub(emailProvider, 'sendPasswordChangeEmail') .callsFake(() => Promise.resolve('email sent')); return request(app) .post('/v1/auth/reset-password') .send({ email: dbUser.email, password: 'updatedPassword2', resetToken: resetToken.resetToken, }) .expect(httpStatus.OK) .then((res) => { expect(res.body).to.be.equal('Password Updated'); }); });
describe('POST /v1/auth/facebook', () => { it('should create a new user and return an accessToken when user does not exist', () => { sandbox.stub(authProviders, 'facebook').callsFake(fakeOAuthRequest); return request(app) .post('/v1/auth/facebook') dbUser.email = 'test@test.com'; await User.create(dbUser); sandbox.stub(authProviders, 'facebook').callsFake(fakeOAuthRequest); return request(app) .post('/v1/auth/facebook')
.stub(emailProvider, 'sendPasswordReset') .callsFake(() => Promise.resolve('email sent'));
beforeEach(() => { sandbox.stub(approveCommand, 'promptKeyStorePasswordAsync') .returns(keystorePassword) approveCommand.erc20TokenService = erc20TokenService })
describe('JSTest dependencies', () => { afterEach(() => { sandbox.restore(); }); it('test', () => { const fakeStubs = sourceHelpers.loadSource( helpers.BASE_DIR, 'JSTests/fake_stub.js'); sandbox.stub(sourceHelpers, 'loadResource').callsFake(() => fakeStubs); testLoad('JSTests/load.js', 'JSTests/load_expected.js'); }); });
describe('getTradingWalletAddress', () => { const personalWalletAddress = '0x52daf0caee4cf4e66a9c90dad58c3f0cc4cbf785' test('calls correctly ethapi transactionCallAsync correctly', async() => { const expectedResult = '0xresult' const transactionCallAsyncResponse = `0x000000000000000000000000${expectedResult.substring(2)}` sandbox.stub(ethApiClient, 'transactionCallAsync').returns(transactionCallAsyncResponse) const transactionCallResult = await tradingWalletService.getTradingWalletAddressAsync(personalWalletAddress) expect(transactionCallResult).toEqual(expectedResult) }) })
describe('Controllers: Search#search', () => { afterEach(() => sandbox.reset()) after(() => sandbox.restore()) it('should return an error message if receives an invalid word', async () => { const req = { query: { q: '999' } } const send = sandbox.stub() res.status.returns({ send }) await searchController(req, res) expect(res.status).to.have.been.calledWith(404) expect(send).to.have.been.calledWith({ error: 'Not found!' }) }) })
beforeEach(() => { sampleUser = { id: 123, name: 'foo', email: 'foo@bar.com', save: sandbox.stub().resolves() }; findStub = sandbox.stub(mongoose.Model, 'findById').resolves(sampleUser); deleteStub = sandbox.stub(mongoose.Model, 'remove').resolves('fake_remove_result'); mailerStub = sandbox.stub(mailer, 'sendWelcomeEmail').resolves('fake_email'); });
describe('getBalanceOfAsync', () => { const personalWalletAddress = '0x52daf0caee4cf4e66a9c90dad58c3f0cc4cbf785' test('calls correctly ethapi transactionCallAsync correctly', async() => { const expectedBalance = '10000000000000' sandbox.stub(ethApiClient, 'transactionCallAsync').returns(expectedBalance) const result = await erc20TokenService.getBalanceOfAsync(personalWalletAddress) expect(result).toEqual(expectedBalance) }) })
beforeEach(() => { errorStub = sandbox.stub().callsFake((res, error) => { return res.status(400).json({error: 'fake'}); }); });
describe('Controllers: Dialect#find', () => { afterEach(() => sandbox.reset()) after(() => sandbox.restore()) it('should return an error message if receives an invalid region', async () => { const req = { params: { region: 'does-not-exist' } } const send = sandbox.stub() res.status.returns({ send }) await findDialect(req, res) expect(res.status).to.have.been.calledWith(404) expect(send).to.have.been.calledWith({ error: 'Not found!' }) }) })
afterEach(() => sandbox.restore());
describe('POST /v1/auth/google', () => { it('should create a new user and return an accessToken when user does not exist', () => { sandbox.stub(authProviders, 'google').callsFake(fakeOAuthRequest); return request(app) .post('/v1/auth/google') dbUser.email = 'test@test.com'; await User.create(dbUser); sandbox.stub(authProviders, 'google').callsFake(fakeOAuthRequest); return request(app) .post('/v1/auth/google')