deleteJson('/api/v2/like')->assertStatus(405); }); it('keeps the like routes the frontends actually use', function () { $target = (string) Str::uuid(); $this->getJson("/api/v2/like?view=count&target_id={$target}") ->assertOk() ->assertJsonPath('ok', true); }); it('rejects sentence fulltext without a bearer token', function () { // 这个 view 以前靠 cookie,且未登录时 $userUid 是未定义变量 // $this->error() 默认 400,这是 v2 既有的失败口径,不是这次改出来的 $json = withV1Cookie(['user_uid' => (string) Str::uuid()], fn () => $this ->getJson('/api/v2/sentence?view=fulltext&key=abc') ->assertStatus(400) ->json()); expect($json['ok'])->toBeFalse() ->and($json['message'])->toBe(__('auth.failed')); }); it('serves sentence fulltext to a bearer-authenticated user', function () { $uid = makeStudio('fulltext-user'); $json = $this->getJson('/api/v2/sentence?view=fulltext&key=abc', authHeader($uid)) ->assertOk() ->json(); expect($json['ok'])->toBeTrue() ->and($json['data'])->toHaveKey('rows'); }); it('rejects userdict view=user without a bearer token', function () { $json = withV1Cookie(['user_id' => '1'], fn () => $this ->getJson('/api/v2/userdict?view=user') ->assertStatus(400) ->json()); expect($json['ok'])->toBeFalse() ->and($json['message'])->toBe(__('auth.failed')); }); it('serves userdict view=user to a bearer-authenticated user', function () { $uid = makeStudio('userdict-user'); $json = $this->getJson('/api/v2/userdict?view=user', authHeader($uid)) ->assertOk() ->json(); expect($json['ok'])->toBeTrue() ->and($json['data'])->toHaveKey('rows'); }); it('rejects DELETE /v2/userdict without a bearer token', function () { $json = withV1Cookie(['user_id' => '1'], fn () => $this ->deleteJson('/api/v2/userdict', ['id' => json_encode(['1'])]) ->assertStatus(400) ->json()); expect($json['ok'])->toBeFalse() ->and($json['message'])->toBe(__('auth.failed')); });