Ejemplo n.º 1
0
     $this->fixtures->reset();
 });
 describe("->set()", function () {
     it("sets an error with trying to add a non Chaos entity", function () {
         $payload = new Payload();
         $payload->set(['hello' => 'world']);
         expect($payload->errors())->toBe([['status' => 500, 'code' => 500, 'title' => "The JSON-API serializer only supports Chaos entities."]]);
     });
     it("adds validation errors", function () {
         $validator = Gallery::validator();
         $validator->rule('name', 'not:empty');
         $gallery = Gallery::create();
         $gallery->validates();
         $payload = new Payload();
         $payload->set($gallery);
         expect($payload->errors())->toBe([['status' => 422, 'code' => 0, 'title' => "Validation Error", 'meta' => [['name' => ['is required']]]]]);
     });
 });
 describe("->delete()", function () {
     it("sets a delete payload", function () {
         $this->fixtures->populate('image');
         $payload = new Payload();
         $images = Image::all();
         $payload->delete($images);
         expect($payload->serialize())->toEqual(['data' => [['type' => 'image', 'id' => 1], ['type' => 'image', 'id' => 2], ['type' => 'image', 'id' => 3], ['type' => 'image', 'id' => 4], ['type' => 'image', 'id' => 5]]]);
     });
 });
 describe("->export()", function () {
     it("exports payload as nested array", function () {
         $json = file_get_contents($this->fixture . 'collection.json');
         $payload = Payload::parse($json);