|
| 1 | +import { usecases } from '../../../../../src/team/domain/usecases/index.js'; |
| 2 | +import * as membershipRepository from '../../../../../src/team/infrastructure/repositories/membership.repository.js'; |
| 3 | +import { databaseBuilder, expect, knex, sinon } from '../../../../test-helper.js'; |
| 4 | + |
| 5 | +describe('Integration | Team | Domain | UseCase | disable-own-membership', function () { |
| 6 | + let clock; |
| 7 | + |
| 8 | + beforeEach(function () { |
| 9 | + clock = sinon.useFakeTimers({ now: new Date('2023-08-01T11:15:00Z'), toFake: ['Date'] }); |
| 10 | + }); |
| 11 | + |
| 12 | + afterEach(function () { |
| 13 | + clock.restore(); |
| 14 | + }); |
| 15 | + |
| 16 | + context('success', function () { |
| 17 | + it('disables membership', async function () { |
| 18 | + // given |
| 19 | + const userId = databaseBuilder.factory.buildUser().id; |
| 20 | + |
| 21 | + const organizationId1 = databaseBuilder.factory.buildOrganization().id; |
| 22 | + databaseBuilder.factory.buildMembership({ |
| 23 | + organizationId: organizationId1, |
| 24 | + userId, |
| 25 | + disabledAt: null, |
| 26 | + }); |
| 27 | + |
| 28 | + const organizationId2 = databaseBuilder.factory.buildOrganization().id; |
| 29 | + databaseBuilder.factory.buildMembership({ |
| 30 | + organizationId: organizationId2, |
| 31 | + userId, |
| 32 | + disabledAt: null, |
| 33 | + }); |
| 34 | + |
| 35 | + await databaseBuilder.commit(); |
| 36 | + |
| 37 | + // when |
| 38 | + await usecases.disableOwnOrganizationMembership({ |
| 39 | + organizationId: organizationId1, |
| 40 | + userId, |
| 41 | + membershipRepository: membershipRepository, |
| 42 | + }); |
| 43 | + |
| 44 | + // then |
| 45 | + const userMemberships = await knex('memberships').where('userId', userId).whereNull('disabledAt'); |
| 46 | + expect(userMemberships).to.have.length(1); |
| 47 | + expect(userMemberships[0].organizationId).to.equal(organizationId2); |
| 48 | + }); |
| 49 | + }); |
| 50 | +}); |
0 commit comments