Beispiel #1
0
        it('should remove an existing resource', function() {
          account.transactions.reset([{
            id: '1',
            amount: -5
          }]);

          Player.play({
            dropped: [{
              path: '/users/1/accounts/1/transactions',
              operations: {
                create: [{
                  id: '1',
                  error: {
                    message: 'Amount must be a positive number.'
                  }
                }]
              }
            }]
          }, true);

          this.flush();

          expect(this.requests.length).toEqual(0);
          expect(account.transactions.length).toEqual(0);
        });
Beispiel #2
0
        it('should emit the @delete event', function() {
          var onCreate = jasmine.createSpy('onCreate');
          var onDelete = jasmine.createSpy('onDelete');

          Player.on('transactions:create', onCreate);
          Player.on('transactions:delete', onDelete);

          account.transactions.reset([{
            id: '1',
            amount: -5
          }]);

          Player.play({
            dropped: [{
              path: '/users/1/accounts/1/transactions',
              operations: {
                create: [{
                  id: '1',
                  error: {
                    message: 'Amount must be a positive number.'
                  }
                }]
              }
            }]
          }, true);

          this.flush();

          expect(onCreate).not.toHaveBeenCalled();
          expect(onDelete).toHaveBeenCalledWith('1', {
            path: '/users/1/accounts/1/transactions',
            rollingBack: true,
            selfOrigin: true
          });
        });
Beispiel #3
0
 expect(function() {
   Player.play({
     dropped: [{
       path: '/users/1/accounts/1/transactions',
       operations: {
         create: [{ id: '1', error: {} }]
       }
     }]
   }, true);
 }).not.toThrow();
Beispiel #4
0
        it('should be a NOOP if the resource doesnt exist', function() {
          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                "delete": [{ id: '2' }]
              }
            }]
          });

          expect(this.requests.length).toEqual(0);
          expect(user.accounts.get('1').transactions.length).toEqual(1);
        });
Beispiel #5
0
        it('should be a NOOP if the resource exists', function() {
          user.accounts.get('1').transactions.push({ id: '1' });

          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                create: [{ id: '1' }]
              }
            }]
          });

          expect(this.requests.length).toEqual(0);
        });
Beispiel #6
0
        it('should remove a resource', function() {
          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                "delete": [{ id: '1' }]
              }
            }]
          });

          expect(this.requests.length).toEqual(0);
          expect(user.accounts.get('1').transactions.get('1')).toBeFalsy();
          expect(user.accounts.get('1').transactions.length).toEqual(0);
        });
Beispiel #7
0
        it('should create a resource', function() {
          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                create: [{ id: '1' }]
              }
            }]
          });

          var request = this.requests[0];

          expect(this.requests.length).toEqual(1);
          expect(request.url).toEqual('/users/1/accounts/1/transactions/1');

          this.respondTo(request, 200, {}, {
            id: '1',
            amount: 10.5
          });
        });
Beispiel #8
0
        it('should re-create a resource', function() {
          Player.play({
            dropped: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                "delete": [{ id: '1', error: {} }]
              }
            }]
          }, true);

          expect(this.requests.length).toEqual(1);
          expect(this.requests[0].url).toEqual('/users/1/accounts/1/transactions/1');

          this.respondTo(this.requests[0], 200, {}, {
            id: '1',
            amount: 20
          });

          expect(user.accounts.get('1').transactions.length).toEqual(1);
        });
Beispiel #9
0
        it('should not create a resource if it could not be fetched', function() {
          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                create: [{ id: '1' }]
              }
            }]
          });

          var request = this.requests[0];

          expect(collection.length).toEqual(1);

          expect(this.requests.length).toEqual(1);
          expect(request.url).toEqual('/users/1/accounts/1/transactions/1');

          this.respondTo(request, 404, {}, {});

          expect(collection.length).toEqual(0);
        });
Beispiel #10
0
        it('should emit the @update event', function() {
          var onUpdate = jasmine.createSpy('onUpdate');

          Player.on('transactions:update', onUpdate);

          Player.play({
            dropped: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                update: [{ id: '1', error: {} }]
              }
            }]
          }, true);

          this.respondTo(this.requests[0], 200, {}, {
            id: '1',
            amount: 20
          });

          expect(onUpdate).toHaveBeenCalled();
        });
Beispiel #11
0
      it('should emit events on success', function() {
        var onChange = jasmine.createSpy('onChange');
        var request, args;

        Player.on('transactions:create', onChange);

        user.accounts.reset([{
          id: '1',
          links: {
            transactions: '/users/1/accounts/1/transactions'
          }
        }]);

        Player.play({
          processed: [{
            path: "/users/1/accounts/1/transactions",
            operations: {
              create: [{ id: '1' }]
            }
          }]
        });

        request = this.requests[0];

        expect(this.requests.length).toEqual(1);
        expect(request.url).toEqual('/users/1/accounts/1/transactions/1');

        this.respondTo(request, 200, {
          id: '1',
          amount: 10.5
        });

        this.flush();

        expect(onChange).toHaveBeenCalledWith('1', {
          path: '/users/1/accounts/1/transactions',
          rollingBack: false,
          selfOrigin: false
        });
      });
Beispiel #12
0
        it('should fetch an updated resource that doesnt exist locally', function() {
          Player.play({
            processed: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                update: [{ id: '2' }]
              }
            }]
          });

          var request = this.requests[0];

          expect(this.requests.length).toEqual(1);
          expect(request.url).toEqual('/users/1/accounts/1/transactions/2');

          this.respondTo(request, 200, {}, {
            id: '2',
            amount: 20
          });

          expect(user.accounts.get('1').transactions.get('2').get('amount')).toEqual(20);
        });
Beispiel #13
0
        it('should re-fetch the resource', function() {
          var request;

          Player.play({
            dropped: [{
              path: "/users/1/accounts/1/transactions",
              operations: {
                update: [{ id: '1', error: {} }]
              }
            }]
          }, true);

          request = this.requests[0];

          expect(this.requests.length).toEqual(1);
          expect(request.url).toEqual('/users/1/accounts/1/transactions/1');

          this.respondTo(request, 200, {}, {
            id: '1',
            amount: 20
          });

          expect(user.accounts.get('1').transactions.get('1').get('amount')).toEqual(20);
        });