Skip to content

Instantly share code, notes, and snippets.

@coclav
Last active November 5, 2019 21:50
Show Gist options
  • Save coclav/b0dd9f7eee2d887cfd4566720fce5d6e to your computer and use it in GitHub Desktop.
Save coclav/b0dd9f7eee2d887cfd4566720fce5d6e to your computer and use it in GitHub Desktop.
Skore test block
<?php
/**
* works with laravel route()
* if you want to force a HTTP verb, append it to the route e.g. v1.processes.update.post to force using post instead of the default patch on update
*/
public function getResponse($endpoint, $queryParams = [], $bodyParams = [])
{
// first -- get the right method
$points = explode(".", $endpoint);
$action = $points[sizeof($points) - 1];
switch ($action) {
case "post":
array_pop($points);
/* falls through */
case "store":
$endpoint = implode(".", $points);
return $this->postJson(route($endpoint, $queryParams), $bodyParams);
case "patch":
array_pop($endpoint);
/* falls through */
case "update":
$endpoint = implode(".", $points);
return $this->patchJson(route($endpoint, $queryParams), $bodyParams);
case "delete":
array_pop($endpoint);
/* falls through */
case "destroy":
$endpoint = implode(".", $points);
return $this->deleteJson(route($endpoint, $queryParams));
case "get":
array_pop($endpoint);
/* falls through */
case "index":
case "show":
$endpoint = implode(".", $points);
return $this->getJson(route($endpoint, $queryParams), $bodyParams);
}
}
<?php
$block = [
"v1.processes.update" => [
"admin-canEdit-can-changeStatusOfAProcess-200" [
// generic : "userType-accessType-Can-Description-code => [
"user" => "dev@getskore.com",
"queryParams" => [
"process" => 1,
],
"bodyParams" => [
"status" => "Archived",
],
"tests" => [
"data.attributes.status" => "Archived", ],
"recursive" => "/* reuse test object */
],
// other scenarios for the same endpoint...
],
"another.endpoint" => [ /* ...*/ ],
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment