forum.test.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. const { eq, ok } = require('../../helpers/assert');
  2. const { makeNetwork, makePeer } = require('../../helpers/setup');
  3. describe('forum: publish + list + reply + vote', (t) => {
  4. t('A creates forum thread, lists it', async () => {
  5. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  6. const r = await A.use('forum').createForum('general', 'My title', 'body');
  7. ok(r);
  8. const list = await A.use('forum').listAll('all');
  9. ok(list.length >= 1);
  10. eq(list[0].title, 'My title');
  11. });
  12. t('A replies to own forum', async () => {
  13. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  14. const r = await A.use('forum').createForum('general', 'T', 'b');
  15. await A.use('forum').addMessageToForum(r.key, { text: 'reply text', category: 'general', title: 'reply' });
  16. const result = await A.use('forum').getMessagesByForumId(r.key);
  17. ok(result);
  18. ok(Array.isArray(result.messages));
  19. });
  20. t('A votes on forum', async () => {
  21. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  22. const r = await A.use('forum').createForum('general', 'T', 'b');
  23. await A.use('forum').voteContent(r.key, 1);
  24. });
  25. t('B (other user) sees A forum', async () => {
  26. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net);
  27. A.setActor();
  28. await A.use('forum').createForum('general', 'Hello', 'world');
  29. B.setActor();
  30. const list = await B.use('forum').listAll('all');
  31. ok(list.length >= 1);
  32. });
  33. });