forked from novuhq/novu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'next' into fix/novuhq#4245
- Loading branch information
Showing
159 changed files
with
2,713 additions
and
1,474 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
apps/api/migrations/subscriber-preferences-level/subscriber-preferences-level.migration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import '../../src/config'; | ||
|
||
import { NestFactory } from '@nestjs/core'; | ||
import { PreferenceLevelEnum, SubscriberPreferenceRepository } from '@novu/dal'; | ||
|
||
import { AppModule } from '../../src/app.module'; | ||
|
||
export async function addLevelPropertyToSubscriberPreferences() { | ||
// eslint-disable-next-line no-console | ||
console.log('start migration - add level property to subscriber preferences'); | ||
const app = await NestFactory.create(AppModule, { | ||
logger: false, | ||
}); | ||
|
||
const subscriberPreferenceRepository = app.get(SubscriberPreferenceRepository); | ||
// eslint-disable-next-line no-console | ||
console.log('add level: PreferenceLevelEnum.TEMPLATE to all subscriber preferences without level property'); | ||
|
||
await subscriberPreferenceRepository._model.collection.updateMany( | ||
{ level: { $exists: false }, _templateId: { $exists: true } }, | ||
{ | ||
$set: { level: PreferenceLevelEnum.TEMPLATE }, | ||
} | ||
); | ||
|
||
// eslint-disable-next-line no-console | ||
console.log('end migration- add level property to subscriber preferences'); | ||
|
||
app.close(); | ||
process.exit(0); | ||
} | ||
|
||
addLevelPropertyToSubscriberPreferences(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
apps/api/src/app/events/usecases/parse-event-request/parse-event-request.e2e.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { Test } from '@nestjs/testing'; | ||
import { expect } from 'chai'; | ||
import { v4 as uuid } from 'uuid'; | ||
|
||
import { SubscribersService, UserSession } from '@novu/testing'; | ||
import { SubscriberRepository, NotificationTemplateEntity } from '@novu/dal'; | ||
import { TriggerRecipients } from '@novu/shared'; | ||
|
||
import { SharedModule } from '../../../shared/shared.module'; | ||
import { EventsModule } from '../../events.module'; | ||
import { ParseEventRequestCommand } from './parse-event-request.command'; | ||
import { ParseEventRequest } from './parse-event-request.usecase'; | ||
|
||
describe('ParseEventRequest Usecase', () => { | ||
let session: UserSession; | ||
let subscribersService: SubscribersService; | ||
let parseEventRequestUsecase: ParseEventRequest; | ||
let template: NotificationTemplateEntity; | ||
|
||
beforeEach(async () => { | ||
const moduleRef = await Test.createTestingModule({ | ||
imports: [SharedModule, EventsModule], | ||
providers: [], | ||
}).compile(); | ||
|
||
session = new UserSession(); | ||
await session.initialize(); | ||
|
||
template = await session.createTemplate(); | ||
parseEventRequestUsecase = moduleRef.get<ParseEventRequest>(ParseEventRequest); | ||
subscribersService = new SubscribersService(session.organization._id, session.environment._id); | ||
}); | ||
|
||
it('should throw exception when subscriber id sent as array', async () => { | ||
const transactionId = uuid(); | ||
const subscriberId = [SubscriberRepository.createObjectId()]; | ||
|
||
const command = buildCommand( | ||
session, | ||
transactionId, | ||
[{ subscriberId: subscriberId } as unknown as string], | ||
template.triggers[0].identifier | ||
); | ||
|
||
try { | ||
await parseEventRequestUsecase.execute(command); | ||
} catch (error) { | ||
expect(error.message).to.be.eql( | ||
'subscriberId under property to is type array, which is not allowed please make sure all subscribers ids are strings' | ||
); | ||
} | ||
}); | ||
}); | ||
|
||
const buildCommand = ( | ||
session: UserSession, | ||
transactionId: string, | ||
to: TriggerRecipients, | ||
identifier: string | ||
): ParseEventRequestCommand => { | ||
return ParseEventRequestCommand.create({ | ||
organizationId: session.organization._id, | ||
environmentId: session.environment._id, | ||
to, | ||
transactionId, | ||
userId: session.user._id, | ||
identifier, | ||
payload: {}, | ||
overrides: {}, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.