diff --git a/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.spec.ts b/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.spec.ts index ec2d8415c..8269dc1dd 100644 --- a/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.spec.ts +++ b/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.spec.ts @@ -66,18 +66,16 @@ describe('MySQLUserSubscriptionRepository', () => { it('should count all active subscriptions', async () => { ormRepository.createQueryBuilder = jest.fn().mockImplementation(() => selectQueryBuilder) - selectQueryBuilder.select = jest.fn().mockReturnThis() - selectQueryBuilder.distinct = jest.fn().mockReturnThis() + selectQueryBuilder.groupBy = jest.fn().mockReturnThis() selectQueryBuilder.where = jest.fn().mockReturnThis() selectQueryBuilder.getCount = jest.fn().mockReturnValue(2) const result = await createRepository().countActiveSubscriptions() - expect(selectQueryBuilder.select).toHaveBeenCalledWith('user_uuid') - expect(selectQueryBuilder.distinct).toHaveBeenCalled() expect(selectQueryBuilder.where).toHaveBeenCalledWith('ends_at > :timestamp', { timestamp: 123, }) + expect(selectQueryBuilder.groupBy).toHaveBeenCalledWith('user_uuid') expect(selectQueryBuilder.getCount).toHaveBeenCalled() expect(result).toEqual(2) }) diff --git a/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.ts b/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.ts index 36e204cd6..f3819fbbb 100644 --- a/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.ts +++ b/packages/auth/src/Infra/MySQL/MySQLUserSubscriptionRepository.ts @@ -19,9 +19,8 @@ export class MySQLUserSubscriptionRepository implements UserSubscriptionReposito async countActiveSubscriptions(): Promise { return await this.ormRepository .createQueryBuilder() - .select('user_uuid') - .distinct() .where('ends_at > :timestamp', { timestamp: this.timer.getTimestampInMicroseconds() }) + .groupBy('user_uuid') .getCount() }