|
|
@ -13,16 +13,16 @@ import { |
|
|
AnalyticsService, |
|
|
AnalyticsService, |
|
|
ApiUrlConfig, |
|
|
ApiUrlConfig, |
|
|
DateTime, |
|
|
DateTime, |
|
|
|
|
|
Resource, |
|
|
RuleDto, |
|
|
RuleDto, |
|
|
RuleElementDto, |
|
|
RuleElementDto, |
|
|
RuleElementPropertyDto, |
|
|
RuleElementPropertyDto, |
|
|
RuleEventDto, |
|
|
RuleEventDto, |
|
|
RuleEventsDto, |
|
|
RuleEventsDto, |
|
|
|
|
|
RulesDto, |
|
|
RulesService, |
|
|
RulesService, |
|
|
Version, |
|
|
Version |
|
|
Versioned |
|
|
|
|
|
} from '@app/shared/internal'; |
|
|
} from '@app/shared/internal'; |
|
|
import { RuleCreatedDto } from './rules.service'; |
|
|
|
|
|
|
|
|
|
|
|
describe('RulesService', () => { |
|
|
describe('RulesService', () => { |
|
|
const version = new Version('1'); |
|
|
const version = new Version('1'); |
|
|
@ -107,7 +107,7 @@ describe('RulesService', () => { |
|
|
it('should make get request to get app rules', |
|
|
it('should make get request to get app rules', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
let rules: RuleDto[]; |
|
|
let rules: RulesDto; |
|
|
|
|
|
|
|
|
rulesService.getRules('my-app').subscribe(result => { |
|
|
rulesService.getRules('my-app').subscribe(result => { |
|
|
rules = result; |
|
|
rules = result; |
|
|
@ -118,49 +118,18 @@ describe('RulesService', () => { |
|
|
expect(req.request.method).toEqual('GET'); |
|
|
expect(req.request.method).toEqual('GET'); |
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
|
req.flush([ |
|
|
req.flush({ |
|
|
{ |
|
|
items: [ |
|
|
id: 'id1', |
|
|
ruleResponse(12), |
|
|
created: '2016-12-12T10:10', |
|
|
ruleResponse(13) |
|
|
createdBy: 'CreatedBy1', |
|
|
] |
|
|
lastModified: '2017-12-12T10:10', |
|
|
}); |
|
|
lastModifiedBy: 'LastModifiedBy1', |
|
|
|
|
|
url: 'http://squidex.io/hook', |
|
|
|
|
|
version: '1', |
|
|
|
|
|
trigger: { |
|
|
|
|
|
param1: 1, |
|
|
|
|
|
param2: 2, |
|
|
|
|
|
triggerType: 'ContentChanged' |
|
|
|
|
|
}, |
|
|
|
|
|
action: { |
|
|
|
|
|
param3: 3, |
|
|
|
|
|
param4: 4, |
|
|
|
|
|
actionType: 'Webhook' |
|
|
|
|
|
}, |
|
|
|
|
|
isEnabled: true |
|
|
|
|
|
} |
|
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
expect(rules!).toEqual( |
|
|
expect(rules!).toEqual( |
|
|
[ |
|
|
new RulesDto(2, [ |
|
|
new RuleDto('id1', 'CreatedBy1', 'LastModifiedBy1', |
|
|
createRule(12), |
|
|
DateTime.parseISO_UTC('2016-12-12T10:10'), |
|
|
createRule(13) |
|
|
DateTime.parseISO_UTC('2017-12-12T10:10'), |
|
|
])); |
|
|
version, |
|
|
|
|
|
true, |
|
|
|
|
|
{ |
|
|
|
|
|
param1: 1, |
|
|
|
|
|
param2: 2, |
|
|
|
|
|
triggerType: 'ContentChanged' |
|
|
|
|
|
}, |
|
|
|
|
|
'ContentChanged', |
|
|
|
|
|
{ |
|
|
|
|
|
param3: 3, |
|
|
|
|
|
param4: 4, |
|
|
|
|
|
actionType: 'Webhook' |
|
|
|
|
|
}, |
|
|
|
|
|
'Webhook') |
|
|
|
|
|
]); |
|
|
|
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
it('should make post request to create rule', |
|
|
it('should make post request to create rule', |
|
|
@ -179,7 +148,7 @@ describe('RulesService', () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
let rule: Versioned<RuleCreatedDto>; |
|
|
let rule: RuleDto; |
|
|
|
|
|
|
|
|
rulesService.postRule('my-app', dto).subscribe(result => { |
|
|
rulesService.postRule('my-app', dto).subscribe(result => { |
|
|
rule = result; |
|
|
rule = result; |
|
|
@ -190,18 +159,13 @@ describe('RulesService', () => { |
|
|
expect(req.request.method).toEqual('POST'); |
|
|
expect(req.request.method).toEqual('POST'); |
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
expect(req.request.headers.get('If-Match')).toBeNull(); |
|
|
|
|
|
|
|
|
req.flush({ id: 'id1' }, { |
|
|
req.flush(ruleResponse(12), { |
|
|
headers: { |
|
|
headers: { |
|
|
etag: '1' |
|
|
etag: '1' |
|
|
} |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
expect(rule!).toEqual({ |
|
|
expect(rule!).toEqual(createRule(12)); |
|
|
payload: { |
|
|
|
|
|
id: 'id1' |
|
|
|
|
|
}, |
|
|
|
|
|
version |
|
|
|
|
|
}); |
|
|
|
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
it('should make put request to update rule', |
|
|
it('should make put request to update rule', |
|
|
@ -216,46 +180,88 @@ describe('RulesService', () => { |
|
|
} |
|
|
} |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
rulesService.putRule('my-app', '123', dto, version).subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
update: { method: 'PUT', href: '/api/apps/my-app/rules/123' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let rule: RuleDto; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.putRule('my-app', resource, dto, version).subscribe(result => { |
|
|
|
|
|
rule = result; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123'); |
|
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|
|
|
|
|
req.flush({}); |
|
|
req.flush(ruleResponse(123)); |
|
|
|
|
|
|
|
|
|
|
|
expect(rule!).toEqual(createRule(123)); |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
it('should make put request to enable rule', |
|
|
it('should make put request to enable rule', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
rulesService.enableRule('my-app', '123', version).subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
enable: { method: 'PUT', href: '/api/apps/my-app/rules/123/enable' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let rule: RuleDto; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.enableRule('my-app', resource, version).subscribe(result => { |
|
|
|
|
|
rule = result; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123/enable'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123/enable'); |
|
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|
|
|
|
|
req.flush({}); |
|
|
req.flush(ruleResponse(123)); |
|
|
|
|
|
|
|
|
|
|
|
expect(rule!).toEqual(createRule(123)); |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
it('should make put request to disable rule', |
|
|
it('should make put request to disable rule', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
rulesService.disableRule('my-app', '123', version).subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
disable: { method: 'PUT', href: '/api/apps/my-app/rules/123/disable' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
let rule: RuleDto; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.disableRule('my-app', resource, version).subscribe(result => { |
|
|
|
|
|
rule = result; |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123/disable'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123/disable'); |
|
|
|
|
|
|
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.method).toEqual('PUT'); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
expect(req.request.headers.get('If-Match')).toEqual(version.value); |
|
|
|
|
|
|
|
|
req.flush({}); |
|
|
req.flush(ruleResponse(123)); |
|
|
|
|
|
|
|
|
|
|
|
expect(rule!).toEqual(createRule(123)); |
|
|
})); |
|
|
})); |
|
|
|
|
|
|
|
|
it('should make delete request to delete rule', |
|
|
it('should make delete request to delete rule', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
rulesService.deleteRule('my-app', '123', version).subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
delete: { method: 'DELETE', href: '/api/apps/my-app/rules/123' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.deleteRule('my-app', resource, version).subscribe(); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/123'); |
|
|
|
|
|
|
|
|
@ -322,7 +328,13 @@ describe('RulesService', () => { |
|
|
it('should make put request to enqueue rule event', |
|
|
it('should make put request to enqueue rule event', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
rulesService.enqueueEvent('my-app', '123').subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
update: { method: 'PUT', href: '/api/apps/my-app/rules/events/123' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.enqueueEvent('my-app', resource).subscribe(); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/events/123'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/events/123'); |
|
|
|
|
|
|
|
|
@ -335,7 +347,13 @@ describe('RulesService', () => { |
|
|
it('should make delete request to cancel rule event', |
|
|
it('should make delete request to cancel rule event', |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
inject([RulesService, HttpTestingController], (rulesService: RulesService, httpMock: HttpTestingController) => { |
|
|
|
|
|
|
|
|
rulesService.cancelEvent('my-app', '123').subscribe(); |
|
|
const resource: Resource = { |
|
|
|
|
|
_links: { |
|
|
|
|
|
delete: { method: 'DELETE', href: '/api/apps/my-app/rules/events/123' } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
rulesService.cancelEvent('my-app', resource).subscribe(); |
|
|
|
|
|
|
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/events/123'); |
|
|
const req = httpMock.expectOne('http://service/p/api/apps/my-app/rules/events/123'); |
|
|
|
|
|
|
|
|
@ -344,4 +362,58 @@ describe('RulesService', () => { |
|
|
|
|
|
|
|
|
req.flush({}); |
|
|
req.flush({}); |
|
|
})); |
|
|
})); |
|
|
}); |
|
|
|
|
|
|
|
|
function ruleResponse(id: number, suffix = '') { |
|
|
|
|
|
return { |
|
|
|
|
|
id: `id${id}`, |
|
|
|
|
|
created: `${id % 1000 + 2000}-12-12T10:10`, |
|
|
|
|
|
createdBy: `creator-${id}`, |
|
|
|
|
|
lastModified: `${id % 1000 + 2000}-11-11T10:10`, |
|
|
|
|
|
lastModifiedBy: `modifier-${id}`, |
|
|
|
|
|
isEnabled: id % 2 === 0, |
|
|
|
|
|
trigger: { |
|
|
|
|
|
param1: 1, |
|
|
|
|
|
param2: 2, |
|
|
|
|
|
triggerType: `ContentChanged${id}${suffix}` |
|
|
|
|
|
}, |
|
|
|
|
|
action: { |
|
|
|
|
|
param3: 3, |
|
|
|
|
|
param4: 4, |
|
|
|
|
|
actionType: `Webhook${id}${suffix}` |
|
|
|
|
|
}, |
|
|
|
|
|
version: id, |
|
|
|
|
|
_links: { |
|
|
|
|
|
update: { method: 'PUT', href: `/rules/${id}` } |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
export function createRule(id: number, suffix = '') { |
|
|
|
|
|
const result = new RuleDto( |
|
|
|
|
|
`id${id}`, |
|
|
|
|
|
`creator-${id}`, |
|
|
|
|
|
`modifier-${id}`, |
|
|
|
|
|
DateTime.parseISO_UTC(`${id % 1000 + 2000}-12-12T10:10`), |
|
|
|
|
|
DateTime.parseISO_UTC(`${id % 1000 + 2000}-11-11T10:10`), |
|
|
|
|
|
new Version(`${id}`), |
|
|
|
|
|
id % 2 === 0, |
|
|
|
|
|
{ |
|
|
|
|
|
param1: 1, |
|
|
|
|
|
param2: 2, |
|
|
|
|
|
triggerType: `ContentChanged${id}${suffix}` |
|
|
|
|
|
}, |
|
|
|
|
|
`ContentChanged${id}${suffix}`, |
|
|
|
|
|
{ |
|
|
|
|
|
param3: 3, |
|
|
|
|
|
param4: 4, |
|
|
|
|
|
actionType: `Webhook${id}${suffix}` |
|
|
|
|
|
}, |
|
|
|
|
|
`Webhook${id}${suffix}`); |
|
|
|
|
|
|
|
|
|
|
|
result._links['update'] = { |
|
|
|
|
|
method: 'PUT', href: `/rules/${id}` |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |