utils.tests.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /* eslint-env mocha */
  2. import { Random } from 'meteor/random';
  3. import { expect } from 'chai';
  4. import '../utils';
  5. describe('utils', function() {
  6. describe(allowIsBoardAdmin.name, function() {
  7. it('returns if a board has an admin', function() {
  8. const userId = Random.id();
  9. const board = {
  10. hasAdmin: id => {
  11. return id === userId;
  12. }
  13. };
  14. expect(allowIsBoardAdmin(userId, board)).to.equal(true);
  15. expect(allowIsBoardAdmin(Random.id(), board)).to.equal(false);
  16. });
  17. });
  18. describe(allowIsBoardMember.name, function() {
  19. it('returns if a board has a member', function() {
  20. const userId = Random.id();
  21. const board = {
  22. hasMember: id => {
  23. return id === userId;
  24. }
  25. };
  26. expect(allowIsBoardMember(userId, board)).to.equal(true);
  27. expect(allowIsBoardMember(Random.id(), board)).to.equal(false);
  28. });
  29. });
  30. describe(allowIsAnyBoardMember.name, function() {
  31. it('returns if any board has a member', function() {
  32. const userId = Random.id();
  33. const boardsExpectedTrue = [{
  34. hasMember: id => {
  35. return id === userId;
  36. }
  37. }];
  38. expect(allowIsAnyBoardMember(userId, boardsExpectedTrue)).to.equal(true);
  39. expect(allowIsAnyBoardMember(Random.id(), boardsExpectedTrue)).to.equal(false);
  40. const boardsExpectedFalse = [{
  41. hasMember: () => false
  42. }];
  43. expect(allowIsAnyBoardMember(userId, boardsExpectedFalse)).to.equal(false);
  44. expect(allowIsAnyBoardMember(Random.id(), boardsExpectedFalse)).to.equal(false);
  45. });
  46. });
  47. describe(allowIsBoardMemberCommentOnly.name, function() {
  48. it('returns if a board has a member that is not comment-only member', function() {
  49. const userId = Random.id();
  50. const board = {
  51. hasMember: id => {
  52. return id === userId;
  53. },
  54. hasCommentOnly: id => {
  55. return id !== userId;
  56. }
  57. };
  58. expect(allowIsBoardMemberCommentOnly(userId, board)).to.equal(true);
  59. expect(allowIsBoardMemberCommentOnly(Random.id(), board)).to.equal(false);
  60. });
  61. });
  62. describe(allowIsBoardMemberNoComments.name, function() {
  63. it('returns if a board has a member that has comment any comments', function() {
  64. const userId = Random.id();
  65. const board = {
  66. hasMember: id => {
  67. return id === userId;
  68. },
  69. hasNoComments: id => {
  70. return id !== userId;
  71. }
  72. };
  73. expect(allowIsBoardMemberNoComments(userId, board)).to.equal(true);
  74. expect(allowIsBoardMemberNoComments(Random.id(), board)).to.equal(false);
  75. });
  76. });
  77. describe(allowIsBoardMemberByCard.name, function() {
  78. it('returns if the board for a given card has a member', function() {
  79. const userId = Random.id();
  80. const board = {
  81. hasMember: id => {
  82. return id === userId;
  83. }
  84. };
  85. const card = {
  86. board: () => board
  87. };
  88. expect(allowIsBoardMemberByCard(userId, card)).to.equal(true);
  89. expect(allowIsBoardMemberByCard(Random.id(), card)).to.equal(false);
  90. });
  91. });
  92. });