Example #1
0
    context('with a pain with exactly matching ID in DB', function() {
      var id = 'an id';
      var painToHeal = {
        id: id,
        description: 'a description',
      };
      currentPainsPromise.is(R.always(Promise.resolve([painToHeal])));
      expectedNewPains.is(R.always([]));
      description.is(R.always(id));

      context('with no other pains in DB', function() {
        currentPainsPromise.is(R.always(Promise.resolve([painToHeal])));
        expectedNewPains.is(R.always([]));

        itHealsThePain(painToHeal);
      });

      context('with other pains in DB as well', function() {
        var otherPain = {
          id: 'other id',
          description: 'other description',
        };
        currentPainsPromise.is(R.always(Promise.resolve([otherPain, painToHeal])));
        expectedNewPains.is(R.always([otherPain]));

        itHealsThePain(painToHeal);
      });
    });
 [R.map(value => R.cond([
   [
     R.equals(selected),
     R.always(option({ value, selected: true }, props.render(value))),
   ],
   [R.T, R.always(option({ value }, props.render(value)))],
 ])(value), values)]
Example #3
0
export function textForValue (value) {
  return cond([
    [isNil, always(NULL_TEXT)],
    [x => typeof x === 'boolean', always(value ? TRUE_TEXT : FALSE_TEXT)],
    [T, identity]
  ])(value)
}
        it('should returns first argument identity if not undefined', () => {
            const obj = { test: true };

            expect(helpers.defaults(1, R.always('DEFAULT'))).toEqual(1);
            expect(helpers.defaults(false, R.always('DEFAULT'))).toEqual(false);
            expect(helpers.defaults(obj, R.always('DEFAULT'))).toBe(obj);
        });
Example #5
0
File: cd.js Project: lpan/rebash
const getPath = (currentPath, homePath) => cond([
  [equals('~'), always(homePath)],
  [equals('.'), always(currentPath)],
  [equals('..'), always(init(currentPath))],
  [isAbsolutePath, splitPath],
  [T, flip(append)(currentPath)],
]);
Example #6
0
 list.map(function (it) {
   return h('tr' + classNames(
     it.status === invoiceStates.ABORTED && 'strikeout'
   ), [
     h('td', [
       h('a', {
         href: '/invoice/' + it.id,
       }, it.id),
     ]),
     h('td', it.invoiceType.name),
     h('td', it.date),
     h('td', it.number),
     h('td', '' + it.amount),
     h('td', R.ifElse(
       R.identity,
       R.concat(''),
       R.always('--')
     )(it.taxRate)),
     h('td', R.ifElse(
       R.prop('taxRate'),
       it => it.taxRate * it.amount / 100 + '',
         R.always('--')
     )(it)),
     h('td', it.accountTerm.name),
     h('td' + classNames(it.status == invoiceStates.AUTHENTICATED
                         && 'ca'), it.status),
     h('td', [
       h('i' + classNames('fa', it.isVat? 'fa-check': 'fa-remove',
                          it.isVat? 'color-success': 'color-gray')),
     ]),
     h('td', (it.vendor || {}).name || '--'),
     h('td', (it.purchaser || {}).name || '--'),
     h('td', it.creator.username),
   ]);
 })
// fishes out the values for the subscriptions in state and returns them
export default (subscriptions, state) => {
  const cleanedState = getCleanedState(state)

  return R.pipe(
    R.map(R.when(R.isNil, R.always(''))),
    R.filter(RS.endsWith('.*')),
    R.map(key => {
      const keyMinusWildcard = R.slice(0, -2, key)
      const value = RS.dotPath(keyMinusWildcard, cleanedState)
      if (R.is(Object, value) && !RS.isNilOrEmpty(value)) {
        return R.pipe(R.keys, R.map(key => `${keyMinusWildcard}.${key}`))(value)
      }
      return []
    }),
    R.concat(R.map(R.when(R.isNil, R.always('')), subscriptions)),
    R.flatten,
    R.reject(RS.endsWith('.*')),
    R.uniq,
    R.sortBy(R.identity),
    R.map(key => ({
      path: key,
      value: RS.isNilOrEmpty(key) ? cleanedState : RS.dotPath(key, cleanedState)
    }))
  )(subscriptions)
}
Example #8
0
const validate = (val, ruleObj) => {
  if (!val) {
    return true;
  }

  let date;
  const dateInputFormat = ruleObj.params[0];
  const dateInput = moment(val, dateInputFormat);
  let offset = Number(ruleObj.params[2]);
  const unit = ruleObj.params[3] || 'days';

  if (ruleObj.params[1].toLowerCase() === NOW) {
    date = moment();
  } else {
    date = moment(ruleObj.params[1], dateInputFormat);
  }

  // Always start with a defaultMessage
  message.toString = R.always(defaultMessage);

  if (offset) {
    if (offset < 0) {
      offset = Math.abs(offset);
      message.toString = R.always(
        '<%= propertyName %> must greater than <%= ruleParams[1] %> minus <%= Math.abs(ruleParams[2]) %> <%= ruleParams[3] %>.'
      );
      date = date.subtract(offset, unit);
    } else {
      message.toString = R.always('<%= propertyName %> must greater than <%= ruleParams[1] %> plus <%= ruleParams[2] %> <%= ruleParams[3] %>.');
      date = date.add(offset, unit);
    }
  }

  return dateInput.isAfter(date, 'day');
};
Example #9
0
const isInRangeInclusive = (min, max) => _.ifElse(
  _.compose(
    _isBetweenInc(min, max)
  , (i) => parseInt(i,10)
  )
, _.always(null)
, _.always(MSG.NOT_IN_RANGE)
)
Example #10
0
export function textForValue (value) {
  return cond([
    [equals(null), always(NULL_TEXT)],
    [equals(undefined), always(UNDEFINED_TEXT)],
    [x => typeof x === 'boolean', always(value ? TRUE_TEXT : FALSE_TEXT)],
    [T, identity]
  ])(value)
}
Example #11
0
var vf = function ([loading, form, obj]) {
  return h(classNames('object-app', loading && 'loading'), [
    h(classNames('header', dirty(obj) && 'dirty'),
      R.ifElse(R.prop('id'), R.always(`编辑用户-${obj.username}`),
               R.always('创建用户'))(obj)),
    form,
  ]);
};
Example #12
0
        context('by the same reporter', function() {
          var aReporter = {id: 1, name: 'a name'};
          previousReporter.is(R.always(aReporter));
          reporter.is(R.always(aReporter))

          it('keeps the DB record the same', function() {
            expect(newPains).to.eql([previousPain()]);
          });
        });
Example #13
0
 it('should append given pair', () => {
     expect(() => cond.append(
         [R.F, R.always(2)]
     )).toNotThrow();
     expect(getter()).toEqual([
         [R.F, R.always(2)],
         [R.T, R.always(null)],
     ]);
 });
Example #14
0
export const AuthRoute = Component => sources => {
  const loggedIn$ = sources.auth$

  return SwitchedComponent({
    ...sources,
    Component$: loggedIn$.map(
      ifElse(Boolean, always(Component), always(Login))
    ),
  })
}
Example #15
0
      context('with other pains in DB as well', function() {
        var otherPain = {
          id: 'other id',
          description: 'other description',
        };
        currentPainsPromise.is(R.always(Promise.resolve([otherPain, painToHeal])));
        expectedNewPains.is(R.always([otherPain]));

        itHealsThePain(painToHeal);
      });
Example #16
0
 const Test = (props) => {
   const { bindToDispatch } = useBdux(props)
   const creators = bindToDispatch({
     test1: R.always({ type: 'test1' }),
     test2: R.always({ type: 'test2' })
   })
   creators.test1()
   creators.test2()
   return null
 }
Example #17
0
 it('should update given pair at given index', () => {
     expect(() => cond.update(
         0,
         [R.F, R.always(3)]
     )).toNotThrow();
     expect(getter()).toEqual([
         [R.F, R.always(3)],
         [R.T, R.always(null)],
     ]);
 });
Example #18
0
 () => [
   R.cond([
     [R.propEq('status', invoiceStates.ABORTED),
       R.always(h('span.ca', '(已作废)'))],
     [R.propEq('status', invoiceStates.AUTHENTICATED),
       R.always(h('span.ca', '(已认证)'))],
     [R.T, R.always('')]
   ])(obj),
   `编辑发票-${obj.number}`,
 ],
Example #19
0
    context('with ID being regex matched', function() {
      currentPainsPromise.is(R.always(Promise.resolve([{
        id: 'an id',
        description: 'a description',
      }])));
      description.is(R.always('.*'));

      it('fails not finding the pain to heal (regex is escaped)', function() {
        expect(error).to.be.instanceof(Error);
      });
    });
Example #20
0
    context('with a different pain in DB', function() {
      currentPainsPromise.is(R.always(Promise.resolve([{
        id: 'an id',
        description: 'a description',
      }])));
      description.is(R.always('something different'));

      it('fails not finding the pain to heal', function() {
        expect(error).to.be.instanceof(Error);
      });
    });
Example #21
0
    context('with a pain with matching description in DB', function() {
      var existingDescription = 'a description';
      var painToHeal = {
        id: 'an id',
        description: existingDescription,
      };
      currentPainsPromise.is(R.always(Promise.resolve([painToHeal])));
      expectedNewPains.is(R.always([]));
      description.is(R.always(existingDescription));

      itHealsThePain(painToHeal);
    });
 it("should be resolved with null if nothing fails", function () {
     var collection = {
         runValidationRules: R.always(BPromise.resolve()),
         dbCollection: {
             insert: R.always(BPromise.resolve())
         }
     };
     return methods.insert(collection, {})
         .then(function (result) {
             (result === null).should.equal(true);
         });
 });
Example #23
0
 GetMore: [[], m => {
   if (m.answers.has_more)
     return R.evolve({
       answersState: R.always('fetching'),
       page: R.inc,
     }, m)
   else
     return R.evolve({
       answersState: R.always('fetching'),
       page: R.always(1),
     }, m)
 }],
Example #24
0
    context('with a pain with partially matching ID in DB', function() {
      var id = 'd9872979-d66a-41a7-a83b-31f13182f9ae';
      var painToHeal = {
        id: id,
        description: 'a description',
      };
      currentPainsPromise.is(R.always(Promise.resolve([painToHeal])));
      expectedNewPains.is(R.always([]));
      description.is(R.always(id.substring(0, 8)));
      currentPainsPromise.is(R.always(Promise.resolve([painToHeal])));

      itHealsThePain(painToHeal);
    });
function detectStatus(obj) {
  const combined = obj.main + obj.sub;
  const isPrivate = R.test(/private/i);
  const isAccessible = R.both(R.test(/unavailable/i), R.complement(R.test(/sorry/i)));
  const isUnavailable = R.either(R.test(/not exist/i), R.both(R.test(/unavailable/i), R.test(/sorry/i)));

  return R.cond([
    [isPrivate, R.always('private')],
    [isAccessible, R.always('accessible')],
    [isUnavailable, R.always('unavailable')],
    [R.T, R.always('unknown')]
  ])(combined);
}
Example #26
0
export const responseToProblem = (response) => {
  if (response instanceof Error) {
    const known = R.contains(response.code, NODEJS_CONNECTION_ERROR_CODES)
    return known ? CONNECTION_ERROR : UNKNOWN_ERROR
  }
  if (R.isNil(response) || !R.has('status')) return UNKNOWN_ERROR
  return R.cond([
    [in200s, R.always(NONE)],
    [in400s, R.always(CLIENT_ERROR)],
    [in500s, R.always(SERVER_ERROR)],
    [R.T, R.always(UNKNOWN_ERROR)]
  ])(response.status || 0)
}
 it("should be resolved with null if nothing fails", function () {
     var collection = {
         runValidationRules: R.always(BPromise.resolve()),
         dbCollection: {
             findOne: R.always({}),
             update: R.always(BPromise.resolve())
         }
     };
     return methods.update(collection, "", patches)
         .then(function (result) {
             (result === null).should.equal(true);
         });
 });
 it("should be rejected if running validation rules fails", function () {
     var collection = {
         runValidationRules: R.always(BPromise.reject(
             new MW.Error(499, "Error message")
         )),
         dbCollection: {
             findOne: R.always({})
         }
     };
     return methods.update(collection, "", patches).should.be.rejectedWith(MW.Error, {
         code: 499,
         message: "Error message"
     });
 });
Example #29
0
        context('by a different reporter', function() {
          var aReporter = {id: 1, name: 'a name'};
          var differentReporter = {id: 2, name: 'different name'};
          previousReporter.is(R.always(differentReporter));
          reporter.is(R.always(aReporter))

          it('updates the DB record to include the other reporter', function() {
            expect(newPains).to.eql([{
              id: previousPain().id,
              description: previousPain().description,
              reporters: [differentReporter, aReporter],
            }]);
          });
        });
 it("should be rejected if inserting fails", function () {
     var collection = {
         runValidationRules: R.always(BPromise.resolve()),
         dbCollection: {
             insert: R.always(BPromise.reject(
                 new MW.Error(599, "Insert error")
             ))
         }
     };
     return methods.insert(collection, {}).should.be.rejectedWith(MW.Error, {
         code: 599,
         message: "Insert error"
     });
 });