| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- const { test, expect } = require('@playwright/test');
- const BASE = 'http' + String.fromCharCode(58, 47, 47) + 'cfc.iwintrue.com';
- async function login(page) {
- const res = await page.request.post(BASE + '/api/admin-auth/login-by-password', {
- data: { phone: '13800138000', password: 'admin123' }
- });
- expect(res.ok()).toBeTruthy();
- const j = await res.json();
- expect(j.code).toBe(200);
- return j.data.token;
- }
- function auth(token) {
- return token ? { Authorization: 'Bearer ' + token } : {};
- }
- test.describe('create all role users', () => {
- test('create accounts', async ({ page }) => {
- const token = await login(page);
- const headers = auth(token);
- const url = BASE + '/api/admin/users/create';
- const roles = [
- { phone: '13900139000', nickname: '文章管理员', role: 'article_admin', realName: '文章' },
- { phone: '13900139001', nickname: '活动管理员', role: 'activity_admin', realName: '活动' },
- { phone: '13900139002', nickname: '商品管理员', role: 'supplier_admin', realName: '商品' },
- { phone: '13900139003', nickname: '供应商管理员', role: 'supplier_admin', realName: '供应商' },
- { phone: '13900139004', nickname: '营养师', role: 'nutritionist', realName: '营养' },
- { phone: '13900139005', nickname: '成长规划师', role: 'teacher', realName: '规划师' },
- ];
- const results = [];
- for (const item of roles) {
- const resp = await page.request.post(url, { data: item, headers });
- const json = await resp.json();
- if (resp.ok() && json.code === 200) {
- results.push({ status: 'ok', ...item });
- } else {
- results.push({ status: 'failed', ...item, code: json.code, message: json.message });
- }
- }
- console.log('\nCREATE RESULT:');
- results.forEach(r => console.log(JSON.stringify(r)));
- expect(results.filter(r => r.status === 'failed').length).toBe(0);
- });
- });
|