Skip to content

Commit

Permalink
fix: replace downloadurl_placeholder with download_link (#162)
Browse files Browse the repository at this point in the history
* fix: replace downloadurl_placeholder with download_link

* fix: update bruno tests to work across environments

* test: fill out assertions in ThemeUpdateControllerTest
  • Loading branch information
chuckadams authored Feb 12, 2025
1 parent 5933325 commit 9b3f07b
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 71 deletions.
11 changes: 2 additions & 9 deletions app/Data/WpOrg/Themes/ThemeUpdateData.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,25 @@ public function __construct(
public ?string $requires_php,
) {}

/**
* Static method to create an instance from a Theme model.
*/
public static function fromModel(Theme $theme): self
{
return new self(
name: $theme->name,
theme: $theme->slug,
new_version: $theme->version,
url: $theme->download_link,
package: "downloadurl_placeholder{$theme->version}",
// requires: $theme->requires['wordpress'] ?? null, // XXX HUH? requires is always a string...
package: $theme->download_link,
requires: $theme->requires,
requires_php: $theme->requires_php,
);
}

/**
* Static method to create an instance from a Theme model.
* @param Collection<int,Theme> $themes
* @return Collection<string,ThemeUpdateData>
*/
public static function fromModelCollection(Collection $themes): Collection
{
return $themes->mapWithKeys(fn($theme) => [
$theme->slug => self::fromModel($theme),
]);
return $themes->mapWithKeys(fn($theme) => [$theme->slug => self::fromModel($theme)]);
}
}
3 changes: 1 addition & 2 deletions bruno/Plugins/Plugins Update Check.bru
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ meta {
seq: 2
}

get {
post {
url: {{API_URL}}/plugins/update-check/:api_version
body: formUrlEncoded
auth: none
Expand All @@ -15,7 +15,6 @@ params:path {
}

headers {
Host: api.wordpress.org
User-Agent: WordPress/6.2.2; http://172.18.0.5/
Accept: */*
Accept-Encoding: deflate, gzip
Expand Down
1 change: 0 additions & 1 deletion bruno/Themes/Themes Update Check.bru
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ params:path {
}

headers {
Host: api.wordpress.org
User-Agent: WordPress/6.2.2; http://172.18.0.5/
Accept: */*
Accept-Encoding: deflate, gzip
Expand Down
6 changes: 1 addition & 5 deletions bruno/collection.bru
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
headers {
Authorization: Bearer {{API_KEY}}
}

docs {
[Public docs are on the Codex](https://codex.wordpress.org/WordPress.org_API)

We can use [OpenAPI Mocker](https://www.npmjs.com/package/open-api-mocker) for using a mock server
}
4 changes: 2 additions & 2 deletions bruno/environments/AspireCloud Production API.bru
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
vars {
API_URL: https://api.aspirecloud.org
DOWNLOADS_URL: https://downloads.aspirecloud.org
API_URL: https://api.aspirecloud.net
DOWNLOADS_URL: https://downloads.aspirecloud.net
}
3 changes: 3 additions & 0 deletions bruno/environments/AspireCloud Staging API.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
vars {
API_URL: https://api.aspirecloud.io
}
1 change: 0 additions & 1 deletion tests/Feature/API/WpOrg/ApiAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
});

// TODO: write test for real auth token

94 changes: 43 additions & 51 deletions tests/Feature/API/WpOrg/ThemeUpdateControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,46 +102,42 @@
"Stylesheet" => "my-theme",
],
],
]), 'translations' => "[]",
]),
'translations' => "[]",
'locale' => "[\"en_US\"]",
], [
'Accept' => 'application/json',
]);

$response->assertStatus(200);
$response->assertJsonCount(1, 'themes')
$response
->assertJsonCount(1, 'themes')
->assertJsonCount(1, 'no_update')
->assertJsonStructure([
->assertJson([
'themes' => [
'my-theme' => [
'name',
'new_version',
'package',
'requires',
'requires_php',
'theme',
'url',
'name' => 'My Theme',
'theme' => 'my-theme',
'new_version' => '1.2.1',
'url' => 'https://api.aspiredev.org/download/my-theme',
'package' => 'https://api.aspiredev.org/download/my-theme',
'requires' => null,
'requires_php' => '5.6',
],
],
'no_update' => [
'my-theme2' => [
'name',
'new_version',
'package',
'requires',
'requires_php',
'theme',
'url',
'name' => 'My Theme2',
'theme' => 'my-theme2',
'new_version' => '2.9',
'url' => 'https://api.aspiredev.org/download/my-theme2',
'package' => 'https://api.aspiredev.org/download/my-theme2',
'requires' => null,
'requires_php' => '5.6',
],
],
'translations',
])
->assertJsonPath('themes.my-theme.name', 'My Theme')
->assertJsonPath('themes.my-theme.new_version', '1.2.1')
->assertJsonPath('themes.my-theme.theme', 'my-theme')
->assertJsonPath('no_update.my-theme2.name', 'My Theme2')
->assertJsonPath('no_update.my-theme2.new_version', '2.9')
->assertJsonPath('no_update.my-theme2.theme', 'my-theme2');
'translations' => [],
]);
});

it('returns theme updates - no_updates', function () {
Expand Down Expand Up @@ -170,43 +166,39 @@
"Stylesheet" => "my-theme",
],
],
]), 'translations' => "[]",
]),
'translations' => "[]",
'locale' => "[\"en_US\"]",
], [
'Accept' => 'application/json',
]);

$response->assertStatus(200);
$response->assertJsonCount(0, 'themes')
$response
->assertJsonCount(0, 'themes')
->assertJsonCount(2, 'no_update')
->assertJsonStructure([
'themes',
->assertJson([
'themes' => [],
'no_update' => [
'my-theme' => [
'name',
'new_version',
'package',
'requires',
'requires_php',
'theme',
'url',
'name' => 'My Theme',
'theme' => 'my-theme',
'new_version' => '1.2.1',
'url' => 'https://api.aspiredev.org/download/my-theme',
'package' => 'https://api.aspiredev.org/download/my-theme',
'requires' => null,
'requires_php' => '5.6',
],
'my-theme2' => [
'name',
'new_version',
'package',
'requires',
'requires_php',
'theme',
'url',
'name' => 'My Theme2',
'theme' => 'my-theme2',
'new_version' => '2.9',
'url' => 'https://api.aspiredev.org/download/my-theme2',
'package' => 'https://api.aspiredev.org/download/my-theme2',
'requires' => null,
'requires_php' => '5.6',
],
],
'translations',
])
->assertJsonPath('no_update.my-theme.name', 'My Theme')
->assertJsonPath('no_update.my-theme.new_version', '1.2.1')
->assertJsonPath('no_update.my-theme.theme', 'my-theme')
->assertJsonPath('no_update.my-theme2.name', 'My Theme2')
->assertJsonPath('no_update.my-theme2.new_version', '2.9')
->assertJsonPath('no_update.my-theme2.theme', 'my-theme2');
'translations' => [],
]);
});

0 comments on commit 9b3f07b

Please sign in to comment.