mirror of
https://github.com/hanzoai/analytics.git
synced 2026-10-30 15:05:29 +00:00
The route tree moves from src/app/api to src/app/v1, and every caller moves with it: the dashboard's useApi base, the tracker and recorder collect paths, the Next headers and rewrites, the container middleware, the compose healthchecks and the Cypress API tests. The /v1/analytics alias is gone; /v1 is the one prefix. The build-time telemetry post to an upstream endpoint nothing serves is deleted. v1-surface.test.ts fails if src/app/api returns or any first-party file names an /api/ path. Claude-Session: https://claude.ai/code/session_011i2AG9nwpiKUCVxAdDzYuU
123 lines
2.9 KiB
TypeScript
123 lines
2.9 KiB
TypeScript
/// <reference types="cypress" />
|
|
import { v4 as uuid } from 'uuid';
|
|
|
|
Cypress.Commands.add('getDataTest', (value: string) => {
|
|
return cy.get(`[data-test=${value}]`);
|
|
});
|
|
|
|
Cypress.Commands.add('logout', () => {
|
|
cy.visit('/logout');
|
|
cy.url().should('include', '/login');
|
|
});
|
|
|
|
Cypress.Commands.add('login', (username: string, password: string) => {
|
|
cy.session([username, password], () => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/v1/auth/login',
|
|
body: {
|
|
username,
|
|
password,
|
|
},
|
|
})
|
|
.then(response => {
|
|
Cypress.env('authorization', `bearer ${response.body.token}`);
|
|
window.localStorage.setItem('hanzo.analytics.auth', JSON.stringify(response.body.token));
|
|
})
|
|
.its('status')
|
|
.should('eq', 200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('addWebsite', (name: string, domain: string) => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/v1/websites',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
body: {
|
|
id: uuid(),
|
|
createdBy: '41e2b680-648e-4b09-bcd7-3e2b10c06264',
|
|
name: name,
|
|
domain: domain,
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('deleteWebsite', (websiteId: string) => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/v1/websites/${websiteId}`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('addUser', (username: string, password: string, role: string) => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/v1/users',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
body: {
|
|
username: username,
|
|
password: password,
|
|
role: role,
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('deleteUser', (userId: string) => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/v1/users/${userId}`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('addTeam', (name: string) => {
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/v1/teams',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
body: {
|
|
name: name,
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|
|
|
|
Cypress.Commands.add('deleteTeam', (teamId: string) => {
|
|
cy.request({
|
|
method: 'DELETE',
|
|
url: `/v1/teams/${teamId}`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
});
|
|
});
|