jobs.test.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. const { eq, ok } = require('../../helpers/assert');
  2. const { makeNetwork, makePeer } = require('../../helpers/setup');
  3. describe('jobs: create + list + subscribe', (t) => {
  4. t('A creates a job', async () => {
  5. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  6. const r = await A.use('jobs').createJob({
  7. title: 'Dev', description: 'd', location: 'remote',
  8. job_type: 'freelancer', job_time: 'partial', vacants: 1, salary: '$50k', requirements: 'JS',
  9. tags: ['code'], status: 'OPEN'
  10. });
  11. ok(r);
  12. const list = await A.use('jobs').listJobs('ALL', A.keypair.id, {});
  13. ok(list.length >= 1);
  14. });
  15. t('B subscribes to A job', async () => {
  16. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net);
  17. A.setActor();
  18. const r = await A.use('jobs').createJob({
  19. title: 'X', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  20. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN'
  21. });
  22. B.setActor();
  23. await B.use('jobs').subscribeToJob(r.key, B.keypair.id);
  24. const j = await B.use('jobs').getJobById(r.key, B.keypair.id);
  25. ok(j);
  26. });
  27. t('A deletes own job', async () => {
  28. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  29. const r = await A.use('jobs').createJob({
  30. title: 'Z', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  31. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN'
  32. });
  33. await A.use('jobs').deleteJob(r.key);
  34. const list = await A.use('jobs').listJobs('ALL', A.keypair.id, {});
  35. const found = list.find(j => j.title === 'Z');
  36. ok(!found);
  37. });
  38. });
  39. describe('jobs: visibility (public / hidden)', (t) => {
  40. t('default visibility is PUBLIC', async () => {
  41. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  42. await A.use('jobs').createJob({
  43. title: 'PublicJob', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  44. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN'
  45. });
  46. const list = await A.use('jobs').listJobs('ALL', A.keypair.id, {});
  47. const job = list.find(j => j.title === 'PublicJob');
  48. eq(job.visibility, 'PUBLIC');
  49. });
  50. t('HIDDEN job is visible to author', async () => {
  51. const net = makeNetwork(); const A = makePeer(net); A.setActor();
  52. await A.use('jobs').createJob({
  53. title: 'SecretJob', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  54. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN', visibility: 'HIDDEN'
  55. });
  56. const list = await A.use('jobs').listJobs('ALL', A.keypair.id, {});
  57. const job = list.find(j => j.title === 'SecretJob');
  58. ok(job);
  59. eq(job.visibility, 'HIDDEN');
  60. });
  61. t('HIDDEN job is filtered out for non-author', async () => {
  62. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net);
  63. A.setActor();
  64. await A.use('jobs').createJob({
  65. title: 'HiddenJob', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  66. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN', visibility: 'HIDDEN'
  67. });
  68. B.setActor();
  69. const list = await B.use('jobs').listJobs('ALL', B.keypair.id, {});
  70. eq(list.find(j => j.title === 'HiddenJob'), undefined);
  71. });
  72. t('HIDDEN job getJobById throws for non-author', async () => {
  73. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net);
  74. A.setActor();
  75. const r = await A.use('jobs').createJob({
  76. title: 'NoPeek', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  77. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN', visibility: 'HIDDEN'
  78. });
  79. B.setActor();
  80. let threw = false;
  81. try { await B.use('jobs').getJobById(r.key, B.keypair.id); } catch (_) { threw = true; }
  82. ok(threw);
  83. });
  84. t('update can flip visibility PUBLIC -> HIDDEN', async () => {
  85. const net = makeNetwork(); const A = makePeer(net); const B = makePeer(net);
  86. A.setActor();
  87. const r = await A.use('jobs').createJob({
  88. title: 'FlipJob', description: 'd', location: 'remote', job_type: 'freelancer', job_time: 'partial',
  89. vacants: 1, salary: '', requirements: '', tags: [], status: 'OPEN'
  90. });
  91. await A.use('jobs').updateJob(r.key, { visibility: 'HIDDEN' });
  92. B.setActor();
  93. const list = await B.use('jobs').listJobs('ALL', B.keypair.id, {});
  94. eq(list.find(j => j.title === 'FlipJob'), undefined);
  95. });
  96. });