重写
This commit is contained in:
@@ -162,6 +162,62 @@ async function authEntry(baseUrl: string) {
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function sendPhoneCode(baseUrl: string, phone: string) {
|
||||
const response = await httpRequest(`${baseUrl}/api/auth/phone/send-code`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
phone,
|
||||
scene: 'login',
|
||||
}),
|
||||
});
|
||||
const payload = (await response.json()) as {
|
||||
ok: boolean;
|
||||
cooldownSeconds: number;
|
||||
expiresInSeconds: number;
|
||||
};
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
assert.equal(payload.ok, true);
|
||||
assert.equal(payload.cooldownSeconds, 60);
|
||||
assert.equal(payload.expiresInSeconds, 300);
|
||||
}
|
||||
|
||||
async function phoneAuthEntry(baseUrl: string) {
|
||||
const phone = '13800138000';
|
||||
|
||||
await sendPhoneCode(baseUrl, phone);
|
||||
|
||||
const response = await httpRequest(`${baseUrl}/api/auth/phone/login`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({
|
||||
phone,
|
||||
code: '123456',
|
||||
}),
|
||||
});
|
||||
const payload = (await response.json()) as {
|
||||
token: string;
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
loginMethod: string;
|
||||
phoneNumberMasked: string | null;
|
||||
};
|
||||
};
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
assert.ok(payload.token);
|
||||
assert.equal(payload.user.loginMethod, 'phone');
|
||||
assert.equal(payload.user.phoneNumberMasked, '138****8000');
|
||||
|
||||
return payload;
|
||||
}
|
||||
|
||||
async function main() {
|
||||
console.log('[server-node:smoke] booting ephemeral Express server');
|
||||
|
||||
@@ -184,27 +240,32 @@ async function main() {
|
||||
console.log('[server-node:smoke] healthz ok');
|
||||
|
||||
const entry = await authEntry(baseUrl);
|
||||
console.log('[server-node:smoke] auth entry ok');
|
||||
console.log('[server-node:smoke] password auth entry ok');
|
||||
|
||||
const phoneEntry = await phoneAuthEntry(baseUrl);
|
||||
console.log('[server-node:smoke] phone auth entry ok');
|
||||
|
||||
const meResponse = await httpRequest(`${baseUrl}/api/auth/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${entry.token}`,
|
||||
Authorization: `Bearer ${phoneEntry.token}`,
|
||||
},
|
||||
});
|
||||
const mePayload = (await meResponse.json()) as {
|
||||
user: {
|
||||
id: string;
|
||||
username: string;
|
||||
loginMethod: string;
|
||||
};
|
||||
};
|
||||
|
||||
assert.equal(meResponse.status, 200);
|
||||
assert.equal(mePayload.user.username, entry.user.username);
|
||||
assert.equal(mePayload.user.username, phoneEntry.user.username);
|
||||
assert.equal(mePayload.user.loginMethod, 'phone');
|
||||
console.log('[server-node:smoke] auth me ok');
|
||||
|
||||
const putSnapshotResponse = await httpRequest(
|
||||
`${baseUrl}/api/runtime/save/snapshot`,
|
||||
withBearer(entry.token, {
|
||||
withBearer(phoneEntry.token, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
gameState: {
|
||||
@@ -235,7 +296,7 @@ async function main() {
|
||||
`${baseUrl}/api/runtime/save/snapshot`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${entry.token}`,
|
||||
Authorization: `Bearer ${phoneEntry.token}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -253,36 +314,41 @@ async function main() {
|
||||
|
||||
const putSettingsResponse = await httpRequest(
|
||||
`${baseUrl}/api/runtime/settings`,
|
||||
withBearer(entry.token, {
|
||||
withBearer(phoneEntry.token, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({
|
||||
musicVolume: 0.3,
|
||||
platformTheme: 'light',
|
||||
}),
|
||||
}),
|
||||
);
|
||||
const putSettingsPayload = (await putSettingsResponse.json()) as {
|
||||
musicVolume: number;
|
||||
platformTheme: string;
|
||||
};
|
||||
|
||||
assert.equal(putSettingsResponse.status, 200);
|
||||
assert.equal(putSettingsPayload.musicVolume, 0.3);
|
||||
assert.equal(putSettingsPayload.platformTheme, 'light');
|
||||
|
||||
const getSettingsResponse = await httpRequest(`${baseUrl}/api/runtime/settings`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${entry.token}`,
|
||||
Authorization: `Bearer ${phoneEntry.token}`,
|
||||
},
|
||||
});
|
||||
const getSettingsPayload = (await getSettingsResponse.json()) as {
|
||||
musicVolume: number;
|
||||
platformTheme: string;
|
||||
};
|
||||
|
||||
assert.equal(getSettingsResponse.status, 200);
|
||||
assert.equal(getSettingsPayload.musicVolume, 0.3);
|
||||
assert.equal(getSettingsPayload.platformTheme, 'light');
|
||||
console.log('[server-node:smoke] runtime settings roundtrip ok');
|
||||
|
||||
const deleteSnapshotResponse = await httpRequest(
|
||||
`${baseUrl}/api/runtime/save/snapshot`,
|
||||
withBearer(entry.token, {
|
||||
withBearer(phoneEntry.token, {
|
||||
method: 'DELETE',
|
||||
}),
|
||||
);
|
||||
@@ -297,7 +363,7 @@ async function main() {
|
||||
`${baseUrl}/api/runtime/save/snapshot`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${entry.token}`,
|
||||
Authorization: `Bearer ${phoneEntry.token}`,
|
||||
},
|
||||
},
|
||||
);
|
||||
@@ -309,7 +375,7 @@ async function main() {
|
||||
|
||||
const logoutResponse = await httpRequest(
|
||||
`${baseUrl}/api/auth/logout`,
|
||||
withBearer(entry.token, {
|
||||
withBearer(phoneEntry.token, {
|
||||
method: 'POST',
|
||||
}),
|
||||
);
|
||||
@@ -322,7 +388,7 @@ async function main() {
|
||||
|
||||
const expiredTokenResponse = await httpRequest(`${baseUrl}/api/auth/me`, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${entry.token}`,
|
||||
Authorization: `Bearer ${phoneEntry.token}`,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user