mirror of
https://github.com/umami-software/umami.git
synced 2026-02-07 06:07:17 +01:00
Create unit test.
This commit is contained in:
parent
ce2a83a09f
commit
e6eb9a487e
4 changed files with 21 additions and 19 deletions
|
|
@ -1,22 +1,19 @@
|
|||
import { WebsiteMetric, NextApiRequestQueryBody } from 'lib/types';
|
||||
import { canViewWebsite } from 'lib/auth';
|
||||
import { useAuth, useCors, useValidate } from 'lib/middleware';
|
||||
import moment from 'moment-timezone';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { badRequest, methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getEventMetrics } from 'queries';
|
||||
import { parseDateRangeQuery } from 'lib/query';
|
||||
import { NextApiRequestQueryBody, WebsiteMetric } from 'lib/types';
|
||||
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
||||
import { NextApiResponse } from 'next';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'next-basics';
|
||||
import { getEventMetrics } from 'queries';
|
||||
import * as yup from 'yup';
|
||||
import { TimezoneTest } from 'lib/yup';
|
||||
|
||||
const unitTypes = ['year', 'month', 'hour', 'day'];
|
||||
|
||||
export interface WebsiteEventsRequestQuery {
|
||||
id: string;
|
||||
startAt: string;
|
||||
endAt: string;
|
||||
unit: string;
|
||||
timezone: string;
|
||||
unit?: string;
|
||||
timezone?: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
|
|
@ -25,8 +22,8 @@ const schema = {
|
|||
id: yup.string().uuid().required(),
|
||||
startAt: yup.number().integer().required(),
|
||||
endAt: yup.number().integer().moreThan(yup.ref('startAt')).required(),
|
||||
unit: yup.string().required(),
|
||||
timezone: TimezoneTest.required(),
|
||||
unit: UnitTypeTest,
|
||||
timezone: TimezoneTest,
|
||||
url: yup.string(),
|
||||
}),
|
||||
};
|
||||
|
|
@ -49,10 +46,6 @@ export default async (
|
|||
return unauthorized(res);
|
||||
}
|
||||
|
||||
if (!moment.tz.zone(timezone) || !unitTypes.includes(unit)) {
|
||||
return badRequest(res);
|
||||
}
|
||||
|
||||
const events = await getEventMetrics(websiteId, {
|
||||
startDate,
|
||||
endDate,
|
||||
|
|
|
|||
|
|
@ -23,14 +23,14 @@ export interface WebsitePageviewRequestQuery {
|
|||
city?: string;
|
||||
}
|
||||
|
||||
import { TimezoneTest } from 'lib/yup';
|
||||
import { TimezoneTest, UnitTypeTest } from 'lib/yup';
|
||||
import * as yup from 'yup';
|
||||
const schema = {
|
||||
GET: yup.object().shape({
|
||||
id: yup.string().uuid().required(),
|
||||
startAt: yup.number().required(),
|
||||
endAt: yup.number().required(),
|
||||
unit: yup.string(),
|
||||
unit: UnitTypeTest,
|
||||
timezone: TimezoneTest,
|
||||
url: yup.string(),
|
||||
referrer: yup.string(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue