|
|
@@ -1,6 +1,6 @@
|
|
|
const { test, expect } = require('@playwright/test');
|
|
|
const { loginAs, BASE_URL } = require('../../helpers/auth');
|
|
|
-const { assertApiSuccess, authHeaders } = require('../../helpers/utils');
|
|
|
+const { assertApiSuccess, assertApiError, authHeaders } = require('../../helpers/utils');
|
|
|
|
|
|
test.describe('【孩子】小游戏', function() {
|
|
|
var auth;
|
|
|
@@ -9,27 +9,46 @@ test.describe('【孩子】小游戏', function() {
|
|
|
auth = await loginAs(browser, 'child');
|
|
|
});
|
|
|
|
|
|
- test('[场景1] 查看游戏列表 — 返回游戏', async function({ page }) {
|
|
|
- var resp = await page.request.post(BASE_URL + '/api/games/list', {
|
|
|
+ test('[场景1] 保存游戏记录 — 舒尔特方格', async function({ page }) {
|
|
|
+ var resp = await page.request.post(BASE_URL + '/api/game/record', {
|
|
|
headers: authHeaders(auth),
|
|
|
+ data: { childId: 1003, gameCode: 'schulte', score: 95, completionTime: 30 },
|
|
|
});
|
|
|
var data = await assertApiSuccess(resp);
|
|
|
expect(data).toBeTruthy();
|
|
|
});
|
|
|
|
|
|
- test('[场景2] 完成舒尔特方格 — 游戏完成', async function({ page }) {
|
|
|
- var resp = await page.request.post(BASE_URL + '/api/games/schulte/complete', {
|
|
|
+ test('[场景2] 保存游戏记录 — 猜数字', async function({ page }) {
|
|
|
+ var resp = await page.request.post(BASE_URL + '/api/game/record', {
|
|
|
headers: authHeaders(auth),
|
|
|
- data: { childId: 1003, score: 95, timeSpent: 30 },
|
|
|
+ data: { childId: 1003, gameCode: 'guess-number', score: 80, completionTime: 60 },
|
|
|
});
|
|
|
await assertApiSuccess(resp);
|
|
|
});
|
|
|
|
|
|
- test('[场景3] 完成猜数字 — 游戏完成', async function({ page }) {
|
|
|
- var resp = await page.request.post(BASE_URL + '/api/games/guess-number/complete', {
|
|
|
+ test('[场景3] 获取游戏记录历史 — 返回记录', async function({ page }) {
|
|
|
+ var resp = await page.request.post(BASE_URL + '/api/game/history', {
|
|
|
headers: authHeaders(auth),
|
|
|
- data: { childId: 1003, attempts: 5, won: true },
|
|
|
+ data: { childId: 1003, gameCode: 'schulte', page: 1, size: 20 },
|
|
|
});
|
|
|
- await assertApiSuccess(resp);
|
|
|
+ var data = await assertApiSuccess(resp);
|
|
|
+ expect(data).toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
+ test('[场景4] 获取最佳成绩 — 返回成绩', async function({ page }) {
|
|
|
+ var resp = await page.request.post(BASE_URL + '/api/game/best', {
|
|
|
+ headers: authHeaders(auth),
|
|
|
+ data: { childId: 1003 },
|
|
|
+ });
|
|
|
+ var data = await assertApiSuccess(resp);
|
|
|
+ expect(data).toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
+ test('[场景5] 保存游戏记录失败 — 空childId期望错误', async function({ page }) {
|
|
|
+ var resp = await page.request.post(BASE_URL + '/api/game/record', {
|
|
|
+ headers: authHeaders(auth),
|
|
|
+ data: {},
|
|
|
+ });
|
|
|
+ await assertApiError(resp);
|
|
|
});
|
|
|
});
|