supertest('https://192.168.99.100:8080') .post('/notification/sendEmail') .send({payload}) .end((err, res) => { if (err) { reject(new Error('An error occured with the payment service, err: ' + err)) } resolve(res.body) })
it('should handle insert error', async () => { const expectedResult = 'Invalid team specified'; await request(server) .post('/') .expect(400) .expect((response) => { assert.ok(response.text.includes(expectedResult)); }); });
test(`post http method for load route`, async () => { const query = { measures: ['Foo.bar'], order: [ ['Foo.bar', 'asc'], ['Foo.foo', 'desc'], ], }; const res = await request(app) .post(`/cubejs-api/v1/load`) .set('Content-type', 'application/json') .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .send({ query }) .expect(200); expect(res.body.query.order).toStrictEqual([ { id: 'Foo.bar', desc: false }, { id: 'Foo.foo', desc: true }, ]); expect(res.body.query.measures).toStrictEqual(['Foo.bar']); });
api.post('/booking') .send({user, booking}) .expect((res) => {
.post(getURL('/articles')) .set('Accept', 'application/json') .set('Cookie', `token=${token}`)
.post('/booking') .send({user, booking}) .expect((res) => {
.post('/payment/makePurchase') .send({paymentOrder: testPayment}) .expect((res) => {
.post('/notification/sendEmail') .send({payload}) .expect((res) => {
supertest('https://192.168.99.100:8080') .post('/payment/makePurchase') .send({paymentOrder}) .end((err, res) => { if (err) { reject(new Error('An error occured with the payment service, err: ' + err)) } resolve(res.body.paid) })
it('should return a new accessToken when refreshToken and email match', async () => { await RefreshToken.create(refreshToken); return request(app) .post('/v1/auth/refresh-token') .send({ email: dbUser.email, refreshToken: refreshToken.token }) .expect(httpStatus.OK) .then((res) => { expect(res.body).to.have.a.property('accessToken'); expect(res.body).to.have.a.property('refreshToken'); expect(res.body).to.have.a.property('expiresIn'); }); });
test('测试管理员注册,输入两次密码不正确,测试结果注册失败', async () => { const res = await server.post('/api/v1/admin/register').send({ nickname, email, password1: password, password2: password + '1024' }) expect(res.status).toBe(400) })
it('should report error when the refreshToken is expired', async () => { await RefreshToken.create(expiredRefreshToken); return request(app) .post('/v1/auth/refresh-token') .send({ email: dbUser.email, refreshToken: expiredRefreshToken.token }) .expect(httpStatus.UNAUTHORIZED) .then((res) => { expect(res.body.code).to.be.equal(401); expect(res.body.message).to.be.equal('Invalid refresh token.'); }); });
test('测试管理员登录,使用正确的邮箱和错误密码,测试结果应该登录失败', async () => { const res = await server.post('/api/v1/admin/login').send({ email, password: password + '1024' }) expect(res.status).toBe(401); })
test('测试管理员注册,输入不正确的邮箱进行注册,测试结果应该注册失败', async () => { const res = await server.post('/api/v1/admin/register').send({ nickname, email: `not a mail@m`, password1: password, password2: password }) expect(res.status).toBe(400) })