Skip to content

Commit a66dfa4

Browse files
test(appstore): cover stale cache filtering in AppDiscoverFetcher
Verify that stale discover data still removes expired entries after the base fetcher falls back from a failed refresh. Assisted-by: Copilot:gpt-5.6-luna Signed-off-by: Josh <josh.t.richards@gmail.com>
1 parent dbe50ea commit a66dfa4

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

tests/lib/App/AppStore/Fetcher/AppDiscoverFetcherTest.php

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,84 @@ public static function dataGetETag(): array {
115115
'numeric etag' => ['132', false, '{ "ETag": 132 }'],
116116
];
117117
}
118+
119+
public function testGetFiltersExpiredEntriesFromStaleCachedData(): void {
120+
$this->config
121+
->method('getSystemValueString')
122+
->willReturnCallback(function (string $key, string $default): string {
123+
if ($key === 'version') {
124+
return '11.0.0.2';
125+
}
126+
127+
return $default;
128+
});
129+
130+
$this->config
131+
->method('getSystemValueBool')
132+
->willReturnArgument(1);
133+
134+
$this->config
135+
->method('getAppValue')
136+
->willReturnCallback(function (string $app, string $key, string $default): string {
137+
if ($key === 'appstore-fetcher-lastFailure') {
138+
return (string)time();
139+
}
140+
141+
return $default;
142+
});
143+
144+
$folder = $this->createMock(ISimpleFolder::class);
145+
$file = $this->createMock(ISimpleFile::class);
146+
147+
$this->appData
148+
->expects($this->once())
149+
->method('getFolder')
150+
->with('/')
151+
->willReturn($folder);
152+
153+
$folder
154+
->expects($this->once())
155+
->method('getFile')
156+
->with('discover.json')
157+
->willReturn($file);
158+
159+
$now = time();
160+
161+
$file
162+
->expects($this->once())
163+
->method('getContent')
164+
->willReturn(json_encode([
165+
'timestamp' => $now - 3601,
166+
'data' => [
167+
[
168+
'type' => 'post',
169+
'id' => 'active-entry',
170+
'expiryDate' => date('c', $now + 3600),
171+
],
172+
[
173+
'type' => 'post',
174+
'id' => 'expired-entry',
175+
'expiryDate' => date('c', $now - 3600),
176+
],
177+
],
178+
'ncversion' => '11.0.0.2',
179+
]));
180+
181+
$this->timeFactory
182+
->expects($this->exactly(2))
183+
->method('getTime')
184+
->willReturn($now);
185+
186+
$this->clientService
187+
->expects($this->never())
188+
->method('newClient');
189+
190+
$this->assertSame([
191+
[
192+
'type' => 'post',
193+
'id' => 'active-entry',
194+
'expiryDate' => date('c', $now + 3600),
195+
],
196+
], $this->fetcher->get());
197+
}
118198
}

0 commit comments

Comments
 (0)