Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Added optional website ID for creation

eoussamab73a67915da2
diff --git a/cypress/e2e/api-website.cy.ts b/cypress/e2e/api-website.cy.ts
index 3fba48d35..7f7d17c38 100644
--- a/cypress/e2e/api-website.cy.ts
+++ b/cypress/e2e/api-website.cy.ts
@@ -1,3 +1,5 @@
+import { uuid } from '../../src/lib/crypto';
+
describe('Website API tests', () => {
Cypress.session.clearAllSavedSessions();
@@ -65,6 +67,37 @@ describe('Website API tests', () => {
});
});
+ it('Creates a website with a fixed ID.', () => {
+ cy.fixture('websites').then(data => {
+ const websiteCreate = data.websiteCreate;
+ const fixedId = uuid();
+ cy.request({
+ method: 'POST',
+ url: '/api/websites',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ body: { ...websiteCreate, id: fixedId },
+ }).then(response => {
+ expect(response.status).to.eq(200);
+ expect(response.body).to.have.property('id', fixedId);
+ expect(response.body).to.have.property('name', 'Cypress Website');
+ expect(response.body).to.have.property('domain', 'cypress.com');
+
+ // cleanup
+ cy.request({
+ method: 'DELETE',
+ url: `/api/websites/${fixedId}`,
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: Cypress.env('authorization'),
+ },
+ });
+ });
+ });
+ });
+
it('Returns all tracked websites.', () => {
cy.request({
method: 'GET',
diff --git a/src/app/api/websites/route.ts b/src/app/api/websites/route.ts
index b8fb2a0b8..7a2146f87 100644
--- a/src/app/api/websites/route.ts
+++ b/src/app/api/websites/route.ts
@@ -26,6 +26,7 @@ export async function POST(request: Request) {
domain: z.string().max(500),
shareId: z.string().max(50).nullable().optional(),
teamId: z.string().nullable().optional(),
+ id: z.string().uuid().nullable().optional(),
});
const { auth, body, error } = await parseRequest(request, schema);
@@ -34,14 +35,14 @@ export async function POST(request: Request) {
return error();
}
- const { name, domain, shareId, teamId } = body;
+ const { id, name, domain, shareId, teamId } = body;
if ((teamId && !(await canCreateTeamWebsite(auth, teamId))) || !(await canCreateWebsite(auth))) {
return unauthorized();
}
const data: any = {
- id: uuid(),
+ id: id ?? uuid(),
createdBy: auth.user.id,
name,
domain,