Updated Mult-Company Support and added Tax ID Fields
This commit is contained in:
@@ -1634,10 +1634,15 @@ async function main() {
|
||||
const companyHeaders = (id) => ({ ...auth, 'X-Company-Id': String(id) });
|
||||
// Company A is the seeded default; create company B.
|
||||
const companyA = (await request('/api/entities', { headers: auth })).entities[0].id;
|
||||
const companyB = (await request('/api/entities', {
|
||||
method: 'POST', headers: auth, body: JSON.stringify({ name: `Company B ${suffix}`, base_currency: 'USD' })
|
||||
})).entity.id;
|
||||
const companyBEntity = (await request('/api/entities', {
|
||||
method: 'POST', headers: auth,
|
||||
body: JSON.stringify({ name: `Company B ${suffix}`, base_currency: 'USD', federal_tax_id: '12-3456789', state_tax_id: 'ST-001', local_tax_id: 'LOC-9' })
|
||||
})).entity;
|
||||
const companyB = companyBEntity.id;
|
||||
if (!companyB || companyB === companyA) throw new Error('Second company was not created');
|
||||
if (companyBEntity.federal_tax_id !== '12-3456789' || companyBEntity.state_tax_id !== 'ST-001' || companyBEntity.local_tax_id !== 'LOC-9') {
|
||||
throw new Error('Company federal/state/local tax ids did not persist');
|
||||
}
|
||||
|
||||
// A new company auto-seeds its own book set (distinct ids from company A's).
|
||||
const booksA = (await request('/api/books', { headers: companyHeaders(companyA) })).books;
|
||||
@@ -1766,6 +1771,19 @@ async function main() {
|
||||
});
|
||||
if (crossAssign.status !== 404) throw new Error('Assigning an asset from another company should 404');
|
||||
|
||||
// The employee directory is per-company.
|
||||
const empB = (await request('/api/employees', { method: 'POST', headers: companyHeaders(companyB), body: JSON.stringify({ name: 'B Worker', employee_number: `EMP-${suffix}` }) })).employee;
|
||||
if (!empB || empB.entity_id !== companyB) throw new Error('New employee was not scoped to the active company');
|
||||
const empsA = (await request('/api/employees', { headers: companyHeaders(companyA) })).employees;
|
||||
const empsB = (await request('/api/employees', { headers: companyHeaders(companyB) })).employees;
|
||||
if (empsA.some((e) => e.id === empB.id)) throw new Error('Company A sees company B employee');
|
||||
if (!empsB.some((e) => e.id === empB.id)) throw new Error('Company B employee missing');
|
||||
// Company B's employee cannot be attached to a company A assignment (resolves to no employee).
|
||||
const crossEmpAssign = (await request('/api/assignments', {
|
||||
method: 'POST', headers: companyHeaders(companyA), body: JSON.stringify({ asset_id: assetAonly.id, employee_id: empB.id })
|
||||
})).assignment;
|
||||
if (crossEmpAssign.employee_id) throw new Error('A company A assignment accepted a company B employee');
|
||||
|
||||
console.log('Smoke test passed');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user