Skip to content

Commit

Permalink
* fix broken test CursorCodecTest & PostsTreeTest
Browse files Browse the repository at this point in the history
* rename class `BaseQueryTest` to `PostsTreeTest`
@ `App\Tests\PostsQuery`
@ be
  • Loading branch information
n0099 committed Oct 26, 2024
1 parent a1ab17c commit 66d1507
Show file tree
Hide file tree
Showing 4 changed files with 204 additions and 279 deletions.
4 changes: 2 additions & 2 deletions be/src/PostsQuery/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function query(QueryParams $params, ?string $cursor): void
$fid = $params->getUniqueParamValue('fid');

$orderByParam = $params->pick('orderBy')[0];
$this->setOrderByField($orderByParam->value === 'default' ? 'postedAt' : $orderByParam->value);
$this->setOrderByDesc($orderByParam->value === 'default' || $orderByParam->getSub('direction') === 'DESC');
$this->setOrderByField($orderByParam->value === 'default' ? 'postedAt' : $orderByParam->value)
->setOrderByDesc($orderByParam->value === 'default' || $orderByParam->getSub('direction') === 'DESC');

/** @var array<string, array> $cachedUserQueryResult key by param name */
$cachedUserQueryResult = [];
Expand Down
269 changes: 0 additions & 269 deletions be/tests/PostsQuery/BaseQueryTest.php

This file was deleted.

19 changes: 11 additions & 8 deletions be/tests/PostsQuery/CursorCodecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace App\Tests\PostsQuery;

use App\DTO\PostKey\Reply;
use App\DTO\PostKey\SubReply;
use App\DTO\PostKey\Thread;
use App\PostsQuery\CursorCodec;
use Illuminate\Support\Collection;
use PHPUnit\Framework\Attributes\CoversClass;
Expand Down Expand Up @@ -30,31 +33,31 @@ public static function provideEncodeNextCursor(): array
return [[
'AQ,0,Ag,-:____fw,Aw,S:test',
collect([
'threads' => collect([['tid' => 1, 'postedAt' => 0]]),
'replies' => collect([['pid' => 2, 'postedAt' => -2147483649]]),
'subReplies' => collect([['spid' => 3, 'postedAt' => 'test']]),
'threads' => collect([new Thread(1, 'postedAt', 0)]),
'replies' => collect([new Reply(1, 2, 'postedAt', -2147483649)]),
'subReplies' => collect([new SubReply(1, 2, 3, 'postedAt', 'test')]),
]),
]];
}

#[DataProvider('provideDecodeCursor')]
public function testDecodeCursor(string $cursor, array $expected): void
public function testDecodeCursor(string $cursor, Collection $expected): void
{
self::assertEquals(collect($expected), $this->sut->decodeCursor($cursor, 'postedAt'));
self::assertEquals($expected, $this->sut->decodeCursor($cursor, 'postedAt'));
}

public static function provideDecodeCursor(): array
{
return [[
'AQ,0,Ag,-:____fw,Aw,S:test',
[
collect([
'thread' => ['tid' => 1, 'postedAt' => 0],
'reply' => ['pid' => 2, 'postedAt' => -2147483649],
'subReply' => ['spid' => 3, 'postedAt' => 'test'],
],
]),
], [
',,,,0,0',
[],
collect(),
]];
}
}
Loading

0 comments on commit 66d1507

Please sign in to comment.