-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #350 from jaredwray/airhorn-store-crud-methods-for…
…-subscription-and-notification airhorn store crud methods for subscription and notification
- Loading branch information
Showing
4 changed files
with
158 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
import {test, describe, expect} from 'vitest'; | ||
import {AirhornStore} from '../../src/store/airhorn-store.js'; | ||
import {type CreateAirhornNotification, AirhornStore, AirhornNotificationStatus} from '../../src/store/airhorn-store.js'; | ||
import { MongoStoreProvider } from '../../src/store/mongo-store-provider.js'; | ||
import { AirhornProviderType } from '../../src/provider-type.js'; | ||
|
||
const mongoUri = 'mongodb://localhost:27017/airhorn'; | ||
|
||
|
@@ -22,4 +23,115 @@ describe('AirhornStore', async () => { | |
expect(store.provider).toBeDefined(); | ||
expect(store.provider?.uri).toBe('mongodb://localhost:27017/airhornnew'); | ||
}); | ||
|
||
test('Create Subscription', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createSubscription = { | ||
to: '[email protected]', | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
}; | ||
|
||
const subscription = await store.createSubscription(createSubscription); | ||
expect(subscription).toBeDefined(); | ||
expect(subscription.id).toBeDefined(); | ||
expect(subscription.to).toBe(createSubscription.to); | ||
|
||
await store.deleteSubscription(subscription); | ||
}); | ||
|
||
test('Update Subscription', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createSubscription = { | ||
to: '[email protected]', | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
}; | ||
|
||
const subscription = await store.createSubscription(createSubscription); | ||
expect(subscription).toBeDefined(); | ||
subscription.templateName = 'updated-template'; | ||
const updatedSubscription = await store.updateSubscription(subscription); | ||
expect(updatedSubscription).toBeDefined(); | ||
expect(updatedSubscription.id).toStrictEqual(subscription.id); | ||
expect(updatedSubscription.templateName).toBe('updated-template'); | ||
await store.deleteSubscriptionById(updatedSubscription.id); | ||
}); | ||
|
||
test('Get Subscription by Id', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createSubscription = { | ||
to: '[email protected]', | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
}; | ||
|
||
const subscription = await store.createSubscription(createSubscription); | ||
expect(subscription).toBeDefined(); | ||
const subscriptionById = await store.getSubscriptionById(subscription.id); | ||
expect(subscriptionById).toBeDefined(); | ||
expect(subscriptionById.id).toStrictEqual(subscription.id); | ||
await store.deleteSubscriptionById(subscription.id); | ||
}); | ||
|
||
test('Create Notification', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createNotification: CreateAirhornNotification = { | ||
to: '[email protected]', | ||
subscriptionId: '123', | ||
status: AirhornNotificationStatus.QUEUED, | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
providerName: 'smtp-provider', | ||
}; | ||
|
||
const notification = await store.createNotification(createNotification); | ||
expect(notification).toBeDefined(); | ||
expect(notification.id).toBeDefined(); | ||
expect(notification.to).toBe(createNotification.to); | ||
await store.deleteNotification(notification); | ||
}); | ||
|
||
test('Update Notification', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createNotification: CreateAirhornNotification = { | ||
to: '[email protected]', | ||
subscriptionId: '123', | ||
status: AirhornNotificationStatus.QUEUED, | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
providerName: 'smtp-provider', | ||
}; | ||
const notification = await store.createNotification(createNotification); | ||
notification.status = AirhornNotificationStatus.SENT; | ||
const updatedNotification = await store.updateNotification(notification); | ||
expect(updatedNotification).toBeDefined(); | ||
expect(updatedNotification.id).toStrictEqual(notification.id); | ||
expect(updatedNotification.status).toBe(AirhornNotificationStatus.SENT); | ||
await store.deleteNotificationById(updatedNotification.id); | ||
}); | ||
|
||
test('Get Notification by Id', async () => { | ||
const provider = new MongoStoreProvider({uri: mongoUri}); | ||
const store = new AirhornStore(provider); | ||
const createNotification: CreateAirhornNotification = { | ||
to: '[email protected]', | ||
subscriptionId: '123', | ||
status: AirhornNotificationStatus.QUEUED, | ||
templateName: 'test-template', | ||
providerType: AirhornProviderType.SMTP, | ||
providerName: 'smtp-provider', | ||
}; | ||
const notification = await store.createNotification(createNotification); | ||
expect(notification).toBeDefined(); | ||
const notificationById = await store.getNotificationById(notification.id); | ||
expect(notificationById).toBeDefined(); | ||
expect(notificationById.id).toStrictEqual(notification.id); | ||
await store.deleteNotificationById(notification.id); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ describe('MongoStoreProvider Subscriptions', () => { | |
expect(subscription.templateName).toBe('foo.template'); | ||
expect(subscription.providerType).toBe(AirhornProviderType.SMTP); | ||
expect(subscription.externalId).toBe('externalId'); | ||
await provider.deleteSubscription(subscription); | ||
await provider.deleteSubscriptionById(subscription.id); | ||
}); | ||
|
||
test('updateSubscription', async () => { | ||
|
@@ -53,7 +53,7 @@ describe('MongoStoreProvider Subscriptions', () => { | |
subscription = await provider.updateSubscription(subscription); | ||
expect(subscription.to).toBe('[email protected]'); | ||
expect(subscription.modifiedAt.getTime()).toBeGreaterThan(subscription.createdAt.getTime()); | ||
await provider.deleteSubscription(subscription); | ||
await provider.deleteSubscriptionById(subscription.id); | ||
}); | ||
|
||
test('getSubscriptions', async () => { | ||
|
@@ -190,7 +190,7 @@ describe('MongoStoreProvider Notifications', () => { | |
providerName: 'foo.provider', | ||
}; | ||
const notification = await provider.createNotification(createNotification); | ||
await provider.deleteNotification(notification); | ||
await provider.deleteNotificationById(notification.id); | ||
const result = await provider.notificationsCollection.findOne({_id: new ObjectId(notification.id)}); | ||
expect(result).toBeNull(); | ||
}); | ||
|