test(`passes correct token`, async () => { const res = await request(app) .get('/cubejs-api/v1/load?query={}') .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(400); expect(res.body && res.body.error).toStrictEqual( 'Query should contain either measures, dimensions or timeDimensions with granularities in order to be valid' ); });
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']); });
const res = await request(reporter.server).get("/metrics").set("Accept-Encoding", "none"); expect(res.statusCode).toBe(200); expect(res.headers["content-type"]).toBe("text/plain; version=0.0.4; charset=utf-8"); reporter.generatePrometheusResponse.mockClear(); const res = await request(reporter.server).get("/metrics").set("Accept-Encoding", "gzip"); expect(res.statusCode).toBe(200); expect(res.headers["content-type"]).toBe("text/plain; version=0.0.4; charset=utf-8");
test(`order support object format`, async () => { const query = { measures: ['Foo.bar'], order: { 'Foo.bar': 'asc', }, }; const res = await request(app) .get(`/cubejs-api/v1/load?query=${JSON.stringify(query)}`) .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200); expect(res.body.query.order).toStrictEqual([{ id: 'Foo.bar', desc: false }]); });
const res = await request(app) .get(`/cubejs-api/v1/load?${searchParams.toString()}`) .set('Content-type', 'application/json') .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200); .set('Content-type', 'application/json') .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(400); }); .set('Content-type', 'application/json') .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200);
test(`date range padding`, async () => { const res = await request(app) .get( '/cubejs-api/v1/load?query={"measures":["Foo.bar"],"timeDimensions":[{"dimension":"Foo.time","granularity":"hour","dateRange":["2020-01-01","2020-01-01"]}]}' ) .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200); console.log(res.body); expect(res.body.query.timeDimensions[0].dateRange).toStrictEqual([ '2020-01-01T00:00:00.000', '2020-01-01T23:59:59.999', ]); });
test(`null filter values`, async () => { const res = await request(app) .get( '/cubejs-api/v1/load?query={"measures":["Foo.bar"],"filters":[{"dimension":"Foo.id","operator":"equals","values":[null]}]}' ) .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200); console.log(res.body); expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]); });
it('should report error when logged user is not the same as the requested one', async () => { const id = (await User.findOne({ email: dbUsers.branStark.email }))._id; return request(app) .put(`/v1/users/${id}`) .set('Authorization', `Bearer ${userAccessToken}`) .expect(httpStatus.FORBIDDEN) .then((res) => { expect(res.body.code).to.be.equal(httpStatus.FORBIDDEN); expect(res.body.message).to.be.equal('Forbidden'); }); });
it('should not update user when no parameters were given', async () => { delete dbUsers.branStark.password; const id = (await User.findOne(dbUsers.branStark))._id; return request(app) .patch(`/v1/users/${id}`) .set('Authorization', `Bearer ${adminAccessToken}`) .send() .expect(httpStatus.OK) .then((res) => { expect(res.body).to.include(dbUsers.branStark); }); });
test(`order support array of tuples`, async () => { const query = { measures: ['Foo.bar'], order: [ ['Foo.bar', 'asc'], ['Foo.foo', 'desc'], ], }; const res = await request(app) .get(`/cubejs-api/v1/load?query=${JSON.stringify(query)}`) .set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M') .expect(200); expect(res.body.query.order).toStrictEqual([ { id: 'Foo.bar', desc: false }, { id: 'Foo.foo', desc: true }, ]); });