calendars.test.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const { eq, ok } = require('../../helpers/assert');
  2. const { makeNetwork, makePeer } = require('../../helpers/setup');
  3. describe('calendars: create + dates + list', (t) => {
  4. t('A creates calendar with first date', async () => {
  5. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  6. const r = await A.use('calendars').createCalendar({
  7. title: 'Year', status: 'OPEN', deadline: '2026-12-31', tags: ['cal'],
  8. firstDate: '2030-01-01', firstDateLabel: 'NY', firstNote: 'happy',
  9. tribeId: null
  10. });
  11. ok(r);
  12. const list = await A.use('calendars').listAll({ filter: 'all', viewerId: A.keypair.id });
  13. ok(list.length >= 1);
  14. });
  15. t('A adds date to own calendar', async () => {
  16. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  17. const r = await A.use('calendars').createCalendar({
  18. title: 'C', status: 'OPEN', deadline: '2026-12-31', tags: [],
  19. firstDate: '2030-01-01', firstDateLabel: '', firstNote: '',
  20. tribeId: null
  21. });
  22. await A.use('calendars').addDate(r.key, '2030-06-01', 'mid-year', null, null, null, null);
  23. const dates = await A.use('calendars').getDatesForCalendar(r.key);
  24. ok(Array.isArray(dates));
  25. ok(dates.length >= 2);
  26. });
  27. t('A closes own calendar by setting status', async () => {
  28. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  29. const r = await A.use('calendars').createCalendar({
  30. title: 'X', status: 'OPEN', deadline: '2026-12-31', tags: [],
  31. firstDate: '2030-01-01', firstDateLabel: '', firstNote: '', tribeId: null
  32. });
  33. const list = await A.use('calendars').listAll({ filter: 'all', viewerId: A.keypair.id });
  34. ok(list.find(c => c.title === 'X'));
  35. });
  36. });