Exemple #1
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
          });
        });
Exemple #2
0
        it('should emit the @create event', function() {
          var onCreate = jasmine.createSpy('onCreate');
          var onDelete = jasmine.createSpy('onDelete');

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

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

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

          expect(onCreate).toHaveBeenCalled();
          expect(onDelete).not.toHaveBeenCalled();
        });
Exemple #3
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
        });
      });