diff --git a/app/Docs/Operations/UpdateRequests/IndexUpdateRequestOperation.php b/app/Docs/Operations/UpdateRequests/IndexUpdateRequestOperation.php index ff3d9302a..4e4a008c2 100644 --- a/app/Docs/Operations/UpdateRequests/IndexUpdateRequestOperation.php +++ b/app/Docs/Operations/UpdateRequests/IndexUpdateRequestOperation.php @@ -82,11 +82,30 @@ public static function create(string $objectId = null): BaseObject * Service location: `name` or `address_line_1` for associated location * Organisation: `name` * Organisation sign up form: `name` for organisation +EOT + ) + ->schema(Schema::string()), + FilterParameter::create(null, 'type') + ->description( + <<<'EOT' +Type to filter by: +* Service update: `services` +* New Service: `new_service_created_by_global_admin` +* Location: `locations` +* Service location: `service_locations` +* Organisation update: `organisations` +* New Organisation: `new_organisation_created_by_global_admin` +* Organisation sign up form: `organisation_sign_up_form` +* Event update: `organisation_events` +* New Event: `new_organisation_event_created_by_org_admin` +* Page update: `pages` +* New Page: `new_page` +* Referral: `referrals` EOT ) ->schema(Schema::string()), IncludeParameter::create(null, ['user']), - SortParameter::create(null, ['entry', 'created_at'], '-created_at') + SortParameter::create(null, ['entry','created_at'], '-created_at') ) ->responses( Response::ok()->content( diff --git a/app/Docs/Schemas/Service/UpdateServiceSchema.php b/app/Docs/Schemas/Service/UpdateServiceSchema.php index 32b7bcaf5..d1885b5b2 100644 --- a/app/Docs/Schemas/Service/UpdateServiceSchema.php +++ b/app/Docs/Schemas/Service/UpdateServiceSchema.php @@ -19,6 +19,7 @@ public static function create(string $objectId = null): BaseObject 'name', 'slug', 'type', + 'organisation_id', 'status', 'intro', 'description', @@ -54,6 +55,8 @@ public static function create(string $objectId = null): BaseObject Service::TYPE_CLUB, Service::TYPE_GROUP ), + Schema::string('organisation_id') + ->format(static::FORMAT_UUID), Schema::string('status') ->enum(Service::STATUS_ACTIVE, Service::STATUS_INACTIVE), Schema::integer('score') diff --git a/app/Http/Controllers/Core/V1/UpdateRequestController.php b/app/Http/Controllers/Core/V1/UpdateRequestController.php index 60321d8a3..c91d27a19 100644 --- a/app/Http/Controllers/Core/V1/UpdateRequestController.php +++ b/app/Http/Controllers/Core/V1/UpdateRequestController.php @@ -5,6 +5,7 @@ use App\Events\EndpointHit; use App\Http\Controllers\Controller; use App\Http\Filters\UpdateRequest\EntryFilter; +use App\Http\Filters\UpdateRequest\TypeFilter; use App\Http\Requests\UpdateRequest\DestroyRequest; use App\Http\Requests\UpdateRequest\IndexRequest; use App\Http\Requests\UpdateRequest\ShowRequest; @@ -44,6 +45,7 @@ public function index(IndexRequest $request): AnonymousResourceCollection AllowedFilter::scope('location_id'), AllowedFilter::scope('organisation_id'), AllowedFilter::custom('entry', new EntryFilter()), + AllowedFilter::custom('type', new TypeFilter()), ]) ->allowedIncludes(['user']) ->allowedSorts([ diff --git a/app/Http/Filters/UpdateRequest/TypeFilter.php b/app/Http/Filters/UpdateRequest/TypeFilter.php new file mode 100644 index 000000000..bc34ffde0 --- /dev/null +++ b/app/Http/Filters/UpdateRequest/TypeFilter.php @@ -0,0 +1,22 @@ +whereIn('updateable_type', (array)$value); + } +} diff --git a/app/Http/Requests/OrganisationEvent/StoreRequest.php b/app/Http/Requests/OrganisationEvent/StoreRequest.php index 2b9f65f3e..eb0e37350 100644 --- a/app/Http/Requests/OrganisationEvent/StoreRequest.php +++ b/app/Http/Requests/OrganisationEvent/StoreRequest.php @@ -53,8 +53,8 @@ function ($attribute, $value, $fail) { ], 'title' => ['required', 'string', 'min:1', 'max:255'], 'slug' => ['string', 'min:1', 'max:255', new Slug()], - 'start_date' => ['required', 'date_format:Y-m-d', 'after:today', new DateSanity($this)], - 'end_date' => ['required', 'date_format:Y-m-d', new DateSanity($this)], + 'start_date' => ['required', 'date_format:Y-m-d', new DateSanity($this)], + 'end_date' => ['required', 'date_format:Y-m-d', 'after_or_equal:today', new DateSanity($this)], 'start_time' => ['required', 'date_format:H:i:s', new DateSanity($this)], 'end_time' => ['required', 'date_format:H:i:s', new DateSanity($this)], 'intro' => ['required', 'string', 'min:1', 'max:300'], diff --git a/app/Http/Requests/OrganisationEvent/UpdateRequest.php b/app/Http/Requests/OrganisationEvent/UpdateRequest.php index 517e5c91b..0516f7932 100644 --- a/app/Http/Requests/OrganisationEvent/UpdateRequest.php +++ b/app/Http/Requests/OrganisationEvent/UpdateRequest.php @@ -60,8 +60,8 @@ public function rules(): array $this->organisation_event->slug ), ], - 'start_date' => ['date_format:Y-m-d', 'after:today', new DateSanity($this)], - 'end_date' => ['date_format:Y-m-d', new DateSanity($this)], + 'start_date' => ['date_format:Y-m-d', new DateSanity($this)], + 'end_date' => ['date_format:Y-m-d', 'after_or_equal:today', new DateSanity($this)], 'start_time' => ['date_format:H:i:s', new DateSanity($this)], 'end_time' => ['date_format:H:i:s', new DateSanity($this)], 'intro' => ['string', 'min:1', 'max:300'], diff --git a/app/Models/Scopes/UserScopes.php b/app/Models/Scopes/UserScopes.php index 9e1dc717f..413f0fb82 100644 --- a/app/Models/Scopes/UserScopes.php +++ b/app/Models/Scopes/UserScopes.php @@ -59,10 +59,10 @@ public function getHighestRoleOrderSql(): array $bindings = [ Role::superAdmin()->id, + Role::globalAdmin()->id, Role::organisationAdmin()->id, Role::serviceAdmin()->id, Role::serviceWorker()->id, - Role::globalAdmin()->id, Role::contentAdmin()->id, ]; diff --git a/app/Models/Service.php b/app/Models/Service.php index 1559987a2..fdb20c675 100644 --- a/app/Models/Service.php +++ b/app/Models/Service.php @@ -5,6 +5,7 @@ use App\Contracts\AppliesUpdateRequests; use App\Emails\Email; use App\Http\Requests\Service\UpdateRequest as UpdateServiceRequest; +use App\Http\Resources\OrganisationResource; use App\Models\Mutators\ServiceMutators; use App\Models\Relationships\ServiceRelationships; use App\Models\Scopes\ServiceScopes; @@ -327,6 +328,10 @@ public function applyUpdateRequest(UpdateRequest $updateRequest): UpdateRequest */ public function getData(array $data): array { + if (isset($data['organisation_id'])) { + $data['organisation'] = new OrganisationResource(Organisation::find($data['organisation_id'])); + } + return $data; } diff --git a/app/Search/ElasticSearch/ServiceEloquentMapper.php b/app/Search/ElasticSearch/ServiceEloquentMapper.php index 6114b5256..a90656600 100644 --- a/app/Search/ElasticSearch/ServiceEloquentMapper.php +++ b/app/Search/ElasticSearch/ServiceEloquentMapper.php @@ -24,7 +24,7 @@ public function paginate(SearchRequestBuilder $esQuery, int $page = null, int $p $page = page($page); $perPage = per_page($perPage); - $esQuery->load(['serviceLocations'], Service::class); + $esQuery->load(['serviceLocations.location'], Service::class); $queryRequest = $esQuery->buildSearchRequest()->toArray(); diff --git a/tests/Feature/OrganisationEventsTest.php b/tests/Feature/OrganisationEventsTest.php index 224bd997a..edabdaa7e 100644 --- a/tests/Feature/OrganisationEventsTest.php +++ b/tests/Feature/OrganisationEventsTest.php @@ -1691,6 +1691,186 @@ public function postCreateOrganisationEventWithBookingDetailsRequiresAllBookingF $response->assertStatus(Response::HTTP_OK); } + /** + * @test + */ + public function postCreateOrganisationEventStartsInPastAsOrganisationAdmin200(): void + { + $organisation = Organisation::factory()->create(); + $location = Location::factory()->create(); + $user = User::factory()->create()->makeOrganisationAdmin($organisation); + + Passport::actingAs($user); + + $start = $this->faker->dateTimeBetween('-7 days', '-1 days')->format('Y-m-d'); + $end = $this->faker->dateTimeBetween('+1 days', '+7 days')->format('Y-m-d'); + + $payload = [ + 'title' => $this->faker->sentence(3), + 'start_date' => $start, + 'end_date' => $end, + 'start_time' => '09:00:00', + 'end_time' => '13:00:00', + 'intro' => $this->faker->sentence(), + 'description' => $this->faker->paragraph(), + 'is_free' => true, + 'fees_text' => null, + 'fees_url' => null, + 'organiser_name' => null, + 'organiser_phone' => null, + 'organiser_email' => null, + 'organiser_url' => null, + 'booking_title' => null, + 'booking_summary' => null, + 'booking_url' => null, + 'booking_cta' => null, + 'homepage' => false, + 'is_virtual' => true, + 'location_id' => null, + 'organisation_id' => $organisation->id, + 'category_taxonomies' => [], + ]; + + $response = $this->json('POST', '/core/v1/organisation-events', $payload); + + $response->assertStatus(Response::HTTP_OK); + } + + /** + * @test + */ + public function postCreateOrganisationEventEndsInPastAsOrganisationAdmin422(): void + { + $organisation = Organisation::factory()->create(); + $location = Location::factory()->create(); + $user = User::factory()->create()->makeOrganisationAdmin($organisation); + + Passport::actingAs($user); + + $start = $this->faker->dateTimeBetween('-7 days', '-4 days')->format('Y-m-d'); + $end = $this->faker->dateTimeBetween('-3 days', '-1 days')->format('Y-m-d'); + + $payload = [ + 'title' => $this->faker->sentence(3), + 'start_date' => $start, + 'end_date' => $end, + 'start_time' => '09:00:00', + 'end_time' => '13:00:00', + 'intro' => $this->faker->sentence(), + 'description' => $this->faker->paragraph(), + 'is_free' => true, + 'fees_text' => null, + 'fees_url' => null, + 'organiser_name' => null, + 'organiser_phone' => null, + 'organiser_email' => null, + 'organiser_url' => null, + 'booking_title' => null, + 'booking_summary' => null, + 'booking_url' => null, + 'booking_cta' => null, + 'homepage' => false, + 'is_virtual' => true, + 'location_id' => null, + 'organisation_id' => $organisation->id, + 'category_taxonomies' => [], + ]; + + $response = $this->json('POST', '/core/v1/organisation-events', $payload); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** + * @test + */ + public function postCreateOrganisationEventEndsBeforeItStartsAsOrganisationAdmin422(): void + { + $organisation = Organisation::factory()->create(); + $location = Location::factory()->create(); + $user = User::factory()->create()->makeOrganisationAdmin($organisation); + + Passport::actingAs($user); + + $start = $this->faker->dateTimeBetween('+4 days', '+7 days')->format('Y-m-d'); + $end = $this->faker->dateTimeBetween('+1 days', '+3 days')->format('Y-m-d'); + + $payload = [ + 'title' => $this->faker->sentence(3), + 'start_date' => $start, + 'end_date' => $end, + 'start_time' => '09:00:00', + 'end_time' => '13:00:00', + 'intro' => $this->faker->sentence(), + 'description' => $this->faker->paragraph(), + 'is_free' => true, + 'fees_text' => null, + 'fees_url' => null, + 'organiser_name' => null, + 'organiser_phone' => null, + 'organiser_email' => null, + 'organiser_url' => null, + 'booking_title' => null, + 'booking_summary' => null, + 'booking_url' => null, + 'booking_cta' => null, + 'homepage' => false, + 'is_virtual' => true, + 'location_id' => null, + 'organisation_id' => $organisation->id, + 'category_taxonomies' => [], + ]; + + $response = $this->json('POST', '/core/v1/organisation-events', $payload); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + } + + /** + * @test + */ + public function postCreateOrganisationEventStartsTodayAsOrganisationAdmin200(): void + { + $organisation = Organisation::factory()->create(); + $location = Location::factory()->create(); + $user = User::factory()->create()->makeOrganisationAdmin($organisation); + + Passport::actingAs($user); + + $start = Carbon::now()->format('Y-m-d'); + $end = Carbon::now()->addDay()->format('Y-m-d'); + + $payload = [ + 'title' => $this->faker->sentence(3), + 'start_date' => $start, + 'end_date' => $end, + 'start_time' => '09:00:00', + 'end_time' => '21:00:00', + 'intro' => $this->faker->sentence(), + 'description' => $this->faker->paragraph(), + 'is_free' => true, + 'fees_text' => null, + 'fees_url' => null, + 'organiser_name' => null, + 'organiser_phone' => null, + 'organiser_email' => null, + 'organiser_url' => null, + 'booking_title' => null, + 'booking_summary' => null, + 'booking_url' => null, + 'booking_cta' => null, + 'homepage' => false, + 'is_virtual' => true, + 'location_id' => null, + 'organisation_id' => $organisation->id, + 'category_taxonomies' => [], + ]; + + $response = $this->json('POST', '/core/v1/organisation-events', $payload); + + $response->assertStatus(Response::HTTP_OK); + } + /** * Get a single OrganisationEvent */ diff --git a/tests/Feature/PagesTest.php b/tests/Feature/PagesTest.php index 5e586d6bd..8020d6b7d 100644 --- a/tests/Feature/PagesTest.php +++ b/tests/Feature/PagesTest.php @@ -703,7 +703,7 @@ public function createPageAsGuest401(): void $data = [ 'title' => 'A New Page', 'slug' => 'a-new-page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -736,7 +736,7 @@ public function createPageAsServiceWorker403(): void $data = [ 'title' => 'A New Page', 'slug' => 'a-new-page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -769,7 +769,7 @@ public function createPageAsServiceAdmin403(): void $data = [ 'title' => 'A New Page', 'slug' => 'a-new-page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -802,7 +802,7 @@ public function createPageAsOrganisationAdmin403(): void $data = [ 'title' => 'A New Page', 'slug' => 'a-new-page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -834,7 +834,7 @@ public function createPageAsGlobalAdmin403(): void $data = [ 'title' => 'A New Page', 'slug' => 'a-new-page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -870,7 +870,7 @@ public function createPageAsContentAdmin200(): void $data = [ 'title' => 'A New Page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -931,7 +931,7 @@ public function createPageAsSuperAdmin201(): void $data = [ 'title' => 'A New Page', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1098,7 +1098,7 @@ public function createPageAuditCreated(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1179,7 +1179,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Invalid parent id $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1196,7 +1196,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Unknown parent id $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1213,7 +1213,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Invalid content stucture for landing page $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1232,7 +1232,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Invalid order $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1250,7 +1250,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Invalid order $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1268,7 +1268,7 @@ public function createPageAsContentAdminWithInvalidData422(): void // Landing page cannot have parent $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1291,7 +1291,7 @@ public function createPageAsContentAdminWithInvalidData422(): void $this->json('POST', '/core/v1/pages', [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1325,7 +1325,7 @@ public function createChildPageAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1384,7 +1384,7 @@ public function createChildPageInheritParentStatusAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1443,7 +1443,7 @@ public function createInformationPageRootAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1504,7 +1504,7 @@ public function createLandingPageAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1600,7 +1600,7 @@ public function createPageAfterSiblingAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1662,7 +1662,7 @@ public function createFirstChildPageAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1732,7 +1732,7 @@ public function createPageWithImagePNGAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1803,7 +1803,7 @@ public function createPageWithImageJPGAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1939,7 +1939,7 @@ public function createInformationPageWithCollectionsAsContentAdmin422(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -1976,7 +1976,7 @@ public function createLandingPageWithCollectionsAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2086,7 +2086,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2113,7 +2113,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2140,7 +2140,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2167,7 +2167,7 @@ public function createInformationPageWithCallToActionAsContentAdmin422(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2210,7 +2210,7 @@ public function createInformationPageWithCallToActionAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2251,7 +2251,7 @@ public function createLandingPageWithCallToActionsAsContentAdmin200(): void $data = [ 'title' => $this->faker->sentence(), - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2343,7 +2343,7 @@ public function createPageWithSameTitleAsExistingPageIncrementsSlugAsContentAdmi $data = [ 'title' => 'Test Page Title', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ @@ -2412,7 +2412,7 @@ public function createPageWithSlugAsContentAdmin201(): void $data = [ 'title' => 'Test Page Title', 'slug' => 'different-slug', - 'excerpt' => substr($this->faker->paragraph(2), 0, 149), + 'excerpt' => trim(substr($this->faker->paragraph(2), 0, 149)), 'content' => [ 'introduction' => [ 'content' => [ diff --git a/tests/Feature/Search/ServiceTest.php b/tests/Feature/Search/ServiceTest.php index 6fda95bab..5dec84958 100644 --- a/tests/Feature/Search/ServiceTest.php +++ b/tests/Feature/Search/ServiceTest.php @@ -33,7 +33,10 @@ protected function setUp(): void public function test_guest_can_search(): void { - Service::factory()->create(['name' => 'This is a test']); + $service = Service::factory()->create(['name' => 'This is a test']); + $serviceLocation = ServiceLocation::factory()->create([ + 'service_id' => $service->id, + ]); sleep(1); @@ -93,7 +96,11 @@ public function test_guest_can_search(): void 'last_modified_at', 'created_at', 'updated_at', - 'service_locations', + 'service_locations' => [ + [ + 'location', + ], + ], 'cqc_location_id', ], ], diff --git a/tests/Feature/ServicesTest.php b/tests/Feature/ServicesTest.php index 9c791f476..9f8673dc4 100644 --- a/tests/Feature/ServicesTest.php +++ b/tests/Feature/ServicesTest.php @@ -4826,7 +4826,7 @@ public function global_admin_can_update_organisation_id(): void $response = $this->json('PUT', "/core/v1/services/{$service->id}", $payload); $response->assertStatus(Response::HTTP_OK); - $response->assertJsonFragment(['data' => $payload]); + $response->assertJsonFragment($payload); $updateRequestId = $response->json()['id']; @@ -4881,7 +4881,8 @@ public function global_admin_can_update_organisation_id_with_preview_only(): voi )); $response->assertStatus(Response::HTTP_OK); - $response->assertJsonFragment(['id' => null, 'data' => $payload]); + $response->assertJsonFragment(['id' => null]); + $response->assertJsonFragment($payload); } /** @@ -4905,7 +4906,7 @@ public function global_admin_cannot_update_one_with_auto_approval(): void $response = $this->json('PUT', "/core/v1/services/{$service->id}", $payload); $response->assertStatus(Response::HTTP_OK); - $response->assertJsonFragment(['data' => $payload]); + $response->assertJsonFragment($payload); $data = UpdateRequest::query() ->where('updateable_type', UpdateRequest::EXISTING_TYPE_SERVICE) @@ -5063,24 +5064,6 @@ public function global_admin_cannot_delete_one(): void $response = $this->json('DELETE', "/core/v1/services/{$service->id}"); $response->assertStatus(Response::HTTP_FORBIDDEN); - - // $this->assertDatabaseHas((new Service())->getTable(), ['id' => $service->id]); - - // //Then an update request should be created for the new service - // $updateRequest = UpdateRequest::query() - // ->where('updateable_type', UpdateRequest::DESTROY_TYPE_SERVICE_GLOBAL_ADMIN) - // ->where('updateable_id', $service->id) - // ->firstOrFail(); - - // // Simulate frontend check by making call with UpdateRequest ID. - - // Passport::actingAs(User::factory()->create()->makeSuperAdmin()); - - // $response = $this->json('PUT', "/core/v1/update-requests/{$updateRequest->id}/approve"); - - // $response->assertStatus(Response::HTTP_OK); - - // $this->assertDatabaseMissing((new Service())->getTable(), ['id' => $service->id]); } /** diff --git a/tests/Feature/UpdateRequestsTest.php b/tests/Feature/UpdateRequestsTest.php index bf5aec8b8..9f261d168 100644 --- a/tests/Feature/UpdateRequestsTest.php +++ b/tests/Feature/UpdateRequestsTest.php @@ -250,6 +250,51 @@ public function can_filter_by_entry(): void $response->assertJsonFragment(['id' => $organisationUpdateRequest->id]); } + /** + * @test + */ + public function getFilterUpdateRequestsByTypeAsSuperAdmin200(): void + { + $organisation = Organisation::factory()->create([ + 'name' => 'Name with, comma', + ]); + $creatingUser = User::factory()->create()->makeOrganisationAdmin($organisation); + + $location = Location::factory()->create(); + $locationUpdateRequest = $location->updateRequests()->create([ + 'user_id' => $creatingUser->id, + 'data' => [ + 'address_line_1' => $this->faker->streetAddress(), + 'address_line_2' => null, + 'address_line_3' => null, + 'city' => $this->faker->city(), + 'county' => 'West Yorkshire', + 'postcode' => $this->faker->postcode(), + 'country' => 'United Kingdom', + 'accessibility_info' => null, + ], + ]); + + $organisationUpdateRequest = $organisation->updateRequests()->create([ + 'user_id' => $creatingUser->id, + 'data' => [ + 'name' => 'Test Name', + 'description' => 'Lorem ipsum', + 'url' => 'https://example.com', + 'email' => 'phpunit@example.com', + 'phone' => '07700000000', + ], + ]); + + $superAdminUser = User::factory()->create()->makeSuperAdmin(); + Passport::actingAs($superAdminUser); + $response = $this->json('GET', '/core/v1/update-requests?filter[type]=' . UpdateRequest::EXISTING_TYPE_ORGANISATION); + + $response->assertStatus(Response::HTTP_OK); + $response->assertJsonMissing(['id' => $locationUpdateRequest->id]); + $response->assertJsonFragment(['id' => $organisationUpdateRequest->id]); + } + /** * @test */