Skip to content

Commit

Permalink
Merge pull request #564 from chaynHQ/develop
Browse files Browse the repository at this point in the history
Merge Develop onto Main
  • Loading branch information
eleanorreem authored Aug 14, 2024
2 parents f7c3d34 + 37d6272 commit b639486
Show file tree
Hide file tree
Showing 27 changed files with 855 additions and 653 deletions.
8 changes: 5 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@ Chayn team members usually respond within 3 business days.

Chayn is open to all kinds of contributions, such as:

- additional software tests
- code of any kind (enhancements, new features, maintenance)
- no-code (documenation, translations) \*see spam policy below for accepted documentation changes.
- additional software tests / test coverage
- dependency updates *check Dependabot pull requests
- code (requested features, bug fixes, quality enhancements, maintenance help)
- accessibility and language support.
- no-code (documentation, translations) \*see spam policy below for accepted documentation changes.

# Chayn's Spam Contribution Policy 🚫

Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"dependencies": {
"@mailchimp/mailchimp_marketing": "^3.0.80",
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.3.6",
"@nestjs/common": "^10.3.10",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.6",
"@nestjs/platform-express": "^10.3.7",
Expand All @@ -57,10 +57,10 @@
"typeorm": "^0.3.20"
},
"devDependencies": {
"@eslint/js": "^9.0.0",
"@eslint/js": "^9.8.0",
"@golevelup/ts-jest": "^0.5.0",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/schematics": "^10.1.3",
"@nestjs/testing": "^10.3.10",
"@types/date-fns": "^2.6.0",
"@types/express": "^4.17.21",
Expand All @@ -72,14 +72,14 @@
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"prettier": "^3.3.3",
"supertest": "^7.0.0",
"ts-jest": "^29.2.3",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.16.1"
"typescript-eslint": "^7.17.0"
},
"engines": {
"node": "20.x",
Expand Down
13 changes: 6 additions & 7 deletions src/api/mailchimp/mailchimp-api.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import mailchimp from '@mailchimp/mailchimp_marketing';
import { createHash } from 'crypto';
import { UserEntity } from 'src/entities/user.entity';
import { mailchimpApiKey, mailchimpAudienceId, mailchimpServerPrefix } from 'src/utils/constants';
import { createCompleteMailchimpUserProfile } from 'src/utils/serviceUserProfiles';
import {
ListMember,
ListMemberPartial,
Expand Down Expand Up @@ -34,17 +32,18 @@ export const createMailchimpProfile = async (
}
};

export const batchCreateMailchimpProfiles = async (users: UserEntity[]) => {
export const batchCreateMailchimpProfiles = async (
userProfiles: Partial<UpdateListMemberRequest>[],
) => {
try {
const operations = [];

users.forEach((user) => {
const profileData = createCompleteMailchimpUserProfile(user);
userProfiles.forEach((userProfile, index) => {
operations.push({
method: 'POST',
path: `/lists/${mailchimpAudienceId}/members`,
operation_id: user.id,
body: JSON.stringify(profileData),
operation_id: index,
body: JSON.stringify(userProfile),
});
});

Expand Down
2 changes: 2 additions & 0 deletions src/event-logger/event-logger.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SubscriptionEntity } from 'src/entities/subscription.entity';
import { TherapySessionEntity } from 'src/entities/therapy-session.entity';
import { UserEntity } from 'src/entities/user.entity';
import { PartnerAccessService } from 'src/partner-access/partner-access.service';
import { ServiceUserProfilesService } from 'src/service-user-profiles/service-user-profiles.service';
import { SubscriptionUserService } from 'src/subscription-user/subscription-user.service';
import { SubscriptionService } from 'src/subscription/subscription.service';
import { TherapySessionService } from 'src/therapy-session/therapy-session.service';
Expand All @@ -33,6 +34,7 @@ import { EventLoggerService } from './event-logger.service';
providers: [
EventLoggerService,
UserService,
ServiceUserProfilesService,
SubscriptionUserService,
TherapySessionService,
PartnerAccessService,
Expand Down
2 changes: 2 additions & 0 deletions src/firebase/firebase.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SubscriptionEntity } from 'src/entities/subscription.entity';
import { TherapySessionEntity } from 'src/entities/therapy-session.entity';
import { UserEntity } from 'src/entities/user.entity';
import { PartnerService } from 'src/partner/partner.service';
import { ServiceUserProfilesService } from 'src/service-user-profiles/service-user-profiles.service';
import { SubscriptionUserService } from 'src/subscription-user/subscription-user.service';
import { SubscriptionService } from 'src/subscription/subscription.service';
import { TherapySessionService } from 'src/therapy-session/therapy-session.service';
Expand All @@ -38,6 +39,7 @@ import { FIREBASE, firebaseFactory } from './firebase-factory';
PartnerAccessService,
CourseUserService,
PartnerService,
ServiceUserProfilesService,
SubscriptionUserService,
SubscriptionService,
TherapySessionService,
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async function bootstrap() {
const logger = app.get(Logger);
app.useLogger(logger);
app.useGlobalInterceptors(new LoggingInterceptor());
app.useGlobalPipes(new ValidationPipe({ transform: true }));
app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true }));
app.useGlobalFilters(new ExceptionsFilter());
await app.listen(PORT);
console.log(`Listening on localhost:${PORT}, CTRL+C to stop`);
Expand Down
2 changes: 2 additions & 0 deletions src/partner-access/partner-access.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { SubscriptionEntity } from 'src/entities/subscription.entity';
import { TherapySessionEntity } from 'src/entities/therapy-session.entity';
import { UserEntity } from 'src/entities/user.entity';
import { PartnerService } from 'src/partner/partner.service';
import { ServiceUserProfilesService } from 'src/service-user-profiles/service-user-profiles.service';
import { SubscriptionUserService } from 'src/subscription-user/subscription-user.service';
import { SubscriptionService } from 'src/subscription/subscription.service';
import { TherapySessionService } from 'src/therapy-session/therapy-session.service';
Expand Down Expand Up @@ -42,6 +43,7 @@ import { PartnerAccessService } from './partner-access.service';
UserService,
CourseUserService,
PartnerService,
ServiceUserProfilesService,
SubscriptionUserService,
SubscriptionService,
TherapySessionService,
Expand Down
14 changes: 7 additions & 7 deletions src/partner-access/partner-access.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { sub } from 'date-fns';
import * as crispApi from 'src/api/crisp/crisp-api';
import * as mailchimpApi from 'src/api/mailchimp/mailchimp-api';
import { PartnerEntity } from 'src/entities/partner.entity';
import { ServiceUserProfilesService } from 'src/service-user-profiles/service-user-profiles.service';
import { GetUserDto } from 'src/user/dtos/get-user.dto';
import * as profileData from 'src/utils/serviceUserProfiles';
import {
mockPartnerAccessEntity,
mockPartnerAccessEntityBase,
Expand Down Expand Up @@ -60,6 +60,7 @@ describe('PartnerAccessService', () => {
let repo: Repository<PartnerAccessEntity>;
let mockPartnerRepository: DeepMocked<Repository<PartnerEntity>>;
let mockPartnerAccessRepository: DeepMocked<Repository<PartnerAccessEntity>>;
let mockServiceUserProfilesService: DeepMocked<ServiceUserProfilesService>;

beforeEach(async () => {
jest.clearAllMocks();
Expand All @@ -68,6 +69,7 @@ describe('PartnerAccessService', () => {
mockPartnerAccessRepository = createMock<Repository<PartnerAccessEntity>>(
mockPartnerAccessRepositoryMethods,
);
mockServiceUserProfilesService = createMock<ServiceUserProfilesService>();

const module: TestingModule = await Test.createTestingModule({
providers: [
Expand All @@ -80,6 +82,7 @@ describe('PartnerAccessService', () => {
provide: getRepositoryToken(PartnerEntity),
useValue: mockPartnerRepository,
},
{ provide: ServiceUserProfilesService, useValue: mockServiceUserProfilesService },
],
}).compile();

Expand Down Expand Up @@ -145,8 +148,6 @@ describe('PartnerAccessService', () => {
});
// Mocks that the accesscode already exists
jest.spyOn(repo, 'findOne').mockResolvedValueOnce(mockPartnerAccessEntity);
// Observer on the service user profiles method
jest.spyOn(profileData, 'updateServiceUserProfilesPartnerAccess');

const partnerAccess = await service.assignPartnerAccess(mockUserEntity, '123456');

Expand All @@ -156,10 +157,9 @@ describe('PartnerAccessService', () => {
activatedAt: partnerAccess.activatedAt,
});

expect(profileData.updateServiceUserProfilesPartnerAccess).toHaveBeenCalledWith(
[mockPartnerAccessEntity],
mockUserEntity.email,
);
expect(
mockServiceUserProfilesService.updateServiceUserProfilesPartnerAccess,
).toHaveBeenCalledWith([mockPartnerAccessEntity], mockUserEntity.email);
});

it('should assign partner access even if crisp profile api fails', async () => {
Expand Down
8 changes: 6 additions & 2 deletions src/partner-access/partner-access.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import _ from 'lodash';
import { PartnerEntity } from 'src/entities/partner.entity';
import { UserEntity } from 'src/entities/user.entity';
import { Logger } from 'src/logger/logger';
import { updateServiceUserProfilesPartnerAccess } from 'src/utils/serviceUserProfiles';
import { ServiceUserProfilesService } from 'src/service-user-profiles/service-user-profiles.service';
import { Repository } from 'typeorm';
import { PartnerAccessEntity } from '../entities/partner-access.entity';
import { FEATURES, PartnerAccessCodeStatusEnum } from '../utils/constants';
Expand All @@ -29,6 +29,7 @@ export class PartnerAccessService {
private partnerAccessRepository: Repository<PartnerAccessEntity>,
@InjectRepository(PartnerEntity)
private partnerRepository: Repository<PartnerEntity>,
private readonly serviceUserProfilesService: ServiceUserProfilesService,
) {}

async createPartnerAccess(
Expand Down Expand Up @@ -194,7 +195,10 @@ export class PartnerAccessService {
},
relations: { partner: true },
});
updateServiceUserProfilesPartnerAccess(partnerAccesses, user.email);
this.serviceUserProfilesService.updateServiceUserProfilesPartnerAccess(
partnerAccesses,
user.email,
);
} catch (error) {
this.logger.error(
`Error: Unable to update crisp profile for ${user.email}. Error: ${error.message} `,
Expand Down
11 changes: 11 additions & 0 deletions src/service-user-profiles/service-user-profiles.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from 'src/entities/user.entity';
import { UserService } from 'src/user/user.service';
import { ServiceUserProfilesService } from './service-user-profiles.service';

@Module({
imports: [TypeOrmModule.forFeature([UserEntity])],
providers: [ServiceUserProfilesService, UserService],
})
export class ServiceUserProfilesModule {}
Loading

0 comments on commit b639486

Please sign in to comment.