64 lines
2.7 KiB
JavaScript
64 lines
2.7 KiB
JavaScript
import assert from 'node:assert/strict';
|
|
import { action, section, postFrom } from './operations-helpers.mjs';
|
|
|
|
export default async function operationsAccess(ctx) {
|
|
const { session, day } = ctx;
|
|
for (const [role, label] of [
|
|
['owner', '店主'],
|
|
['assistant', '第一名店员'],
|
|
['assistant2', '第二名店员'],
|
|
]) {
|
|
const page = await ctx.pageFor(role);
|
|
const manager = role === 'owner';
|
|
await section(page, ctx, 'stock');
|
|
await page.locator('#stock-form').waitFor();
|
|
const inventory = await session.get(role, '/api/inventory');
|
|
assert.equal(inventory.canReview, manager);
|
|
const review = action(page, 'inventory-review');
|
|
assert.equal(await review.count(), manager ? 1 : 0);
|
|
await ctx.step(label + '的库存复核权限', async () => {
|
|
if (manager) {
|
|
await postFrom(page, '/api/inventory/review', () => review.click());
|
|
await page.locator('.stock-review-status').getByText('店主复核', { exact: true }).waitFor();
|
|
} else {
|
|
// 页面不给店员提供该按钮。用同样的有效日期、revision 验证 API 自身的权限。
|
|
const denied = await session.request(role, 'POST', '/api/inventory/review', {
|
|
body: { date: day, verified: true, revision: inventory.revision },
|
|
expect: 403,
|
|
});
|
|
assert.equal(denied.status, 403);
|
|
}
|
|
});
|
|
const nav = page.locator('nav [data-tab=team-funds]:visible');
|
|
assert.equal(await nav.count(), manager ? 1 : 0);
|
|
const expectedStatus = manager ? 200 : 403;
|
|
for (const url of ['/api/team-funds?date=' + day, '/api/team-profits?month=' + day.slice(0, 7)]) {
|
|
const r = await session.request(role, 'GET', url, { expect: expectedStatus });
|
|
assert.equal(r.status, expectedStatus);
|
|
}
|
|
if (manager) {
|
|
await nav.click();
|
|
const filter = page.locator('#team-funds-filter');
|
|
await filter.locator('[name=month]').fill('2026-10');
|
|
const [read] = await Promise.all([
|
|
page.waitForResponse(
|
|
r =>
|
|
new URL(r.url()).pathname === '/api/team-profits' &&
|
|
new URL(r.url()).searchParams.get('month') === '2026-10',
|
|
),
|
|
filter.locator('[type=submit]').click(),
|
|
]);
|
|
assert.equal(read.status(), 200);
|
|
await page.locator('#team-funds-content').getByText('助理月度利润').waitFor();
|
|
assert.equal(
|
|
await page.locator('#team-transfer-form:visible, [data-action=inventory-review]:visible').count(),
|
|
0,
|
|
);
|
|
assert.equal(await page.getByRole('button', { name: '登记实际转账' }).count(), 0);
|
|
} else if (ctx.version === 'new') {
|
|
await page.goto(ctx.base + '/next/team-funds');
|
|
await page.locator('nav [data-tab=report][aria-current=page]:visible').waitFor();
|
|
}
|
|
}
|
|
}
|