mass-create-users.spec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. const { test, expect } = require('@playwright/test');
  2. const BASE = 'http' + String.fromCharCode(58, 47, 47) + 'cfc.iwintrue.com';
  3. async function login(page) {
  4. const res = await page.request.post(BASE + '/api/admin-auth/login-by-password', {
  5. data: { phone: '13800138000', password: 'admin123' }
  6. });
  7. expect(res.ok()).toBeTruthy();
  8. const j = await res.json();
  9. expect(j.code).toBe(200);
  10. return j.data.token;
  11. }
  12. function auth(token) {
  13. return token ? { Authorization: 'Bearer ' + token } : {};
  14. }
  15. test.describe('create all role users', () => {
  16. test('create accounts', async ({ page }) => {
  17. const token = await login(page);
  18. const headers = auth(token);
  19. const url = BASE + '/api/admin/users/create';
  20. const roles = [
  21. { phone: '13900139000', nickname: '文章管理员', role: 'article_admin', realName: '文章' },
  22. { phone: '13900139001', nickname: '活动管理员', role: 'activity_admin', realName: '活动' },
  23. { phone: '13900139002', nickname: '商品管理员', role: 'supplier_admin', realName: '商品' },
  24. { phone: '13900139003', nickname: '供应商管理员', role: 'supplier_admin', realName: '供应商' },
  25. { phone: '13900139004', nickname: '营养师', role: 'nutritionist', realName: '营养' },
  26. { phone: '13900139005', nickname: '成长规划师', role: 'teacher', realName: '规划师' },
  27. ];
  28. const results = [];
  29. for (const item of roles) {
  30. const resp = await page.request.post(url, { data: item, headers });
  31. const json = await resp.json();
  32. if (resp.ok() && json.code === 200) {
  33. results.push({ status: 'ok', ...item });
  34. } else {
  35. results.push({ status: 'failed', ...item, code: json.code, message: json.message });
  36. }
  37. }
  38. console.log('\nCREATE RESULT:');
  39. results.forEach(r => console.log(JSON.stringify(r)));
  40. expect(results.filter(r => r.status === 'failed').length).toBe(0);
  41. });
  42. });