forked from StellarSplit/StellarSplit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook-policy.service.spec.ts
More file actions
33 lines (26 loc) · 1.2 KB
/
Copy pathwebhook-policy.service.spec.ts
File metadata and controls
33 lines (26 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import { Test, TestingModule } from '@nestjs/testing';
import { WebhookPolicyService } from './webhook-policy.service';
import { ForbiddenException } from '@nestjs/common';
import { Webhook } from './webhook.entity';
import { AuthUser } from '../auth/types/auth-user.interface';
describe('WebhookPolicyService', () => {
let service: WebhookPolicyService;
beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [WebhookPolicyService],
}).compile();
service = module.get<WebhookPolicyService>(WebhookPolicyService);
});
describe('assertOwnership', () => {
it('should pass if the user owns the webhook', () => {
const user: AuthUser = { id: 'user-1', walletAddress: 'abc', raw: {} };
const webhook = { userId: 'user-1' } as Webhook;
expect(() => service.assertOwnership(user, webhook)).not.toThrow();
});
it('should throw ForbiddenException if the user does not own the webhook', () => {
const user: AuthUser = { id: 'user-1', walletAddress: 'abc', raw: {} };
const webhook = { userId: 'user-2' } as Webhook;
expect(() => service.assertOwnership(user, webhook)).toThrow(ForbiddenException);
});
});
});