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
125 lines
3.6 KiB
TypeScript
125 lines
3.6 KiB
TypeScript
describe('User API tests', () => {
|
|
Cypress.session.clearAllSavedSessions();
|
|
|
|
before(() => {
|
|
cy.login(Cypress.env('admin_user'), Cypress.env('admin_password'));
|
|
});
|
|
|
|
let userId;
|
|
|
|
it('Creates a user.', () => {
|
|
cy.fixture('users').then(data => {
|
|
const userCreate = data.userCreate;
|
|
cy.request({
|
|
method: 'POST',
|
|
url: '/v1/users',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
body: userCreate,
|
|
}).then(response => {
|
|
userId = response.body.id;
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('username', 'cypress1');
|
|
expect(response.body).to.have.property('role', 'user');
|
|
});
|
|
});
|
|
});
|
|
|
|
it('Returns all users. Admin access is required.', () => {
|
|
cy.request({
|
|
method: 'GET',
|
|
url: '/v1/admin/users',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body.data[0]).to.have.property('id');
|
|
expect(response.body.data[0]).to.have.property('username');
|
|
expect(response.body.data[0]).to.have.property('role');
|
|
});
|
|
});
|
|
|
|
it('Updates a user.', () => {
|
|
cy.fixture('users').then(data => {
|
|
const userUpdate = data.userUpdate;
|
|
cy.request({
|
|
method: 'POST',
|
|
url: `/v1/users/${userId}`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
body: userUpdate,
|
|
}).then(response => {
|
|
userId = response.body.id;
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('id', userId);
|
|
expect(response.body).to.have.property('username', 'cypress1');
|
|
expect(response.body).to.have.property('role', 'view-only');
|
|
});
|
|
});
|
|
});
|
|
|
|
it('Gets a user by ID.', () => {
|
|
cy.request({
|
|
method: 'GET',
|
|
url: `/v1/users/${userId}`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('id', userId);
|
|
expect(response.body).to.have.property('username', 'cypress1');
|
|
expect(response.body).to.have.property('role', 'view-only');
|
|
});
|
|
});
|
|
|
|
it('Deletes a user.', () => {
|
|
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);
|
|
expect(response.body).to.have.property('ok', true);
|
|
});
|
|
});
|
|
|
|
it('Gets all websites that belong to a user.', () => {
|
|
cy.request({
|
|
method: 'GET',
|
|
url: `/v1/users/${userId}/websites`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('data');
|
|
});
|
|
});
|
|
|
|
it('Gets all teams that belong to a user.', () => {
|
|
cy.request({
|
|
method: 'GET',
|
|
url: `/v1/users/${userId}/teams`,
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: Cypress.env('authorization'),
|
|
},
|
|
}).then(response => {
|
|
expect(response.status).to.eq(200);
|
|
expect(response.body).to.have.property('data');
|
|
});
|
|
});
|
|
});
|