Skip to content

Commit

Permalink
test (bookmark): test public api works without bookmarks in api response
Browse files Browse the repository at this point in the history
  • Loading branch information
c0nst4ntin committed Jan 2, 2025
1 parent b490c9a commit f7879c6
Show file tree
Hide file tree
Showing 3 changed files with 192 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/Prismic/ApiDataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ public function testWithJsonStringThrowsExceptionForInvalidJson()
ApiData::withJsonString('wtf?');
}

public function testApiDataWorksWithoutBookmarks(){
$json = $this->getJsonFixture('data-without-bookmarks.json');
$data = ApiData::withJsonString($json);

$this->assertInstanceOf(ApiData::class, $data);
$this->assertEquals([], $data->getBookmarks());
}

public function testApiDataHasExpectedValues()
{
$this->assertCount(3, $this->data->getRefs());
Expand Down
19 changes: 19 additions & 0 deletions tests/Prismic/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,25 @@ public function testBookmarkReturnsCorrectDocumentId()
$this->assertNull($api->bookmark('unknown-bookmark'));
}

public function testApiWorksWithoutBookmarks() {
// Create an ApiData object without bookmarks
$data = $this->getJsonFixture('data-without-bookmarks.json');
$apiData = ApiData::withJsonString($data);

// Cache the data
$key = 'https://whatever.prismic.io/api/v2#My-Access-Token';
$cachedData = serialize($apiData);
$this->cache->get($key)->willReturn($cachedData);
$this->httpClient->request()->shouldNotBeCalled();

$api = $this->getApi();

// Test that the bookmarks are empty
$this->assertEmpty($api->bookmarks());
$this->assertNull($api->bookmark('about'));
$this->assertNull($api->bookmark('unknown-bookmark'));
}

public function testFormsReturnsOnlyFormInstances()
{
$api = $this->getApiWithDefaultData();
Expand Down
165 changes: 165 additions & 0 deletions tests/fixtures/data-without-bookmarks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
{
"refs": [
{
"id": "master",
"ref": "UgjWQN_mqa8HvPJY",
"label": "Master",
"isMasterRef": true
},
{
"id": "UkL0hcuvzYUANCrr",
"ref": "UgjWRd_mqbYHvPJa",
"label": "San Francisco Grand opening"
},
{
"id": "SaGrandOpening2ndRef",
"ref": "SaGrandOpening2ndRef",
"label": "San Francisco Grand opening"
}
],
"types": {
"blog-post": "Blog post",
"store": "Store",
"article": "Site-level article",
"selection": "Products selection",
"job-offer": "Job offer",
"product": "Product"
},
"languages": [
{
"id": "en-us",
"name": "English - United States"
},
{
"id": "nl-nl",
"name": "Dutch - Netherlands"
},
{
"id": "es-es",
"name": "Spanish - Spain (Traditional)"
},
{
"id": "fr-fr",
"name": "French - France"
}
],
"tags": ["Cupcake", "Pie", "Featured", "Macaron"],
"forms": {
"everything": {
"method": "GET",
"enctype": "application/x-www-form-urlencoded",
"action": "http://lesbonneschoses.prismic.io/api/v2/documents/search",
"fields": {
"ref": {
"type": "String"
},
"q": {
"type": "String"
}
}
},
"blogs": {
"name": "Blog Posts",
"method": "GET",
"rel": "collection",
"enctype": "application/x-www-form-urlencoded",
"action": "https://lesbonneschoses.prismic.io/api/v2/documents/search",
"fields": {
"ref": {
"type": "String",
"multiple": false
},
"q": {
"default": "[[:d = any(document.type, [\"blog-post\"])]]",
"type": "String",
"multiple": true
},
"lang": {
"type": "String",
"multiple": false
},
"page": {
"type": "Integer",
"multiple": false,
"default": "1"
},
"pageSize": {
"type": "Integer",
"multiple": false,
"default": "20"
},
"after": {
"type": "String",
"multiple": false
},
"fetch": {
"type": "String",
"multiple": false
},
"fetchLinks": {
"type": "String",
"multiple": false
},
"graphQuery": {
"type": "String",
"multiple": false
},
"orderings": {
"type": "String",
"multiple": false
},
"referer": {
"type": "String",
"multiple": false
},
"access_token": {
"default": "a-permanent-access-token",
"type": "String",
"multiple": false
}
}
}
},
"oauth_initiate": "http://lesbonneschoses.prismic.io/auth",
"oauth_token": "http://lesbonneschoses.prismic.io/auth/token",
"experiments" : {
"draft": [
{
"id": "xxxxxxxxxxoGelsX",
"name": "Exp 2",
"variations": [
{
"id": "VDUBBawGAKoGelsZ",
"label": "Base",
"ref": "VDUBBawGALAGelsa"
},
{
"id": "VDUE-awGALAGemME",
"label": "var 1",
"ref": "VDUUmHIKAZQKk9uq"
}
]
}
],
"running": [
{
"googleId": "_UQtin7EQAOH5M34RQq6Dg",
"id": "VDUBBawGAKoGelsX",
"name": "Exp 1",
"variations": [
{
"id": "VDUBBawGAKoGelsZ",
"label": "Base",
"ref": "VDUBBawGALAGelsa"
},
{
"id": "VDUE-awGALAGemME",
"label": "var 1",
"ref": "VDUUmHIKAZQKk9uq"
}
]
}
]
}

}

0 comments on commit f7879c6

Please sign in to comment.