admin = User::factory()->create(); }); test('the files API refuses a numeric expiry instead of failing', function () { $file = File::factory()->create(['uploaded_by' => $this->admin->id]); $token = $this->admin->createToken('t', [ Permission::EditFiles->value, Permission::SetFileExpirationDate->value, ])->plainTextToken; $this->withToken($token)->patchJson("/api/v1/files/{$file->id}", ['expires_at' => NUMBER_DATE]) ->assertUnprocessable() ->assertJsonValidationErrors('expires_at'); }); test('the staff file editor refuses a numeric expiry instead of failing', function () { $file = File::factory()->create(['uploaded_by' => $this->admin->id]); $this->actingAs($this->admin)->patchJson("/files/{$file->id}", [ 'name' => $file->name, 'expires_at' => NUMBER_DATE, ])->assertUnprocessable()->assertJsonValidationErrors('expires_at'); }); test('the bulk editor refuses a numeric expiry instead of failing', function () { $file = File::factory()->create(['uploaded_by' => $this->admin->id]); $this->actingAs($this->admin)->patchJson('/files/bulk-edit', [ 'file_ids' => [$file->id], 'folder_action' => 'no_change', 'description_action' => 'no_change', 'expiration_action' => 'set', 'expires_at' => NUMBER_DATE, ])->assertUnprocessable()->assertJsonValidationErrors('expires_at'); }); test('a new share link refuses a numeric expiry instead of failing', function () { $file = File::factory()->create(['uploaded_by' => $this->admin->id]); $this->actingAs($this->admin)->postJson("/files/{$file->id}/share-links", ['expires_at' => NUMBER_DATE]) ->assertUnprocessable() ->assertJsonValidationErrors('expires_at'); }); test('the client file editor refuses a numeric expiry instead of failing', function () { $role = Role::query()->create(['name' => 'Client Role '.Str::random(6)]); foreach ([Permission::EditFiles, Permission::SetFileExpirationDate] as $permission) { RolePermission::query()->create(['role_id' => $role->id, 'permission' => $permission->value]); } $client = User::factory()->client()->create(['role_id' => $role->id]); $file = File::factory()->create(['uploaded_by' => $client->id]); $this->actingAs($client)->patchJson("/my-files/{$file->id}", [ 'name' => $file->name, 'expires_at' => NUMBER_DATE, ])->assertUnprocessable()->assertJsonValidationErrors('expires_at'); }); test('the same dates written as text are still accepted', function () { $file = File::factory()->create(['uploaded_by' => $this->admin->id]); $token = $this->admin->createToken('t', [ Permission::EditFiles->value, Permission::SetFileExpirationDate->value, ])->plainTextToken; $this->withToken($token)->patchJson("/api/v1/files/{$file->id}", ['expires_at' => '2030-12-31'])->assertOk(); expect($file->refresh()->expires_at)->not->toBeNull(); });