-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathpoetrySlamManagerAPIAuthorizations.test.js
More file actions
175 lines (147 loc) · 6.05 KB
/
poetrySlamManagerAPIAuthorizations.test.js
File metadata and controls
175 lines (147 loc) · 6.05 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// ----------------------------------------------------------------------------
// Initialization of test
// CAP Unit Testing: https://cap.cloud.sap/docs/node.js/cds-test?q=cds.test#run
// ----------------------------------------------------------------------------
'strict';
// Adds cds module
const cds = require('@sap/cds');
// Defines required CDS functions for testing
const { expect, GET, POST, axios, test } = cds.test(__dirname + '/../../..');
const { httpCodes } = require('../../../srv/lib/codes');
// ----------------------------------------------------------------------------
// Tests authorizations for authorized user without role assignment for application
// Authorizations of PoetrySlamManagerAPI with User Peter are tested in poetrySlamManagerAPI.test.js
// ----------------------------------------------------------------------------
describe('Authorizations of PoetrySlamManagerAPI with User Denise (authenticated user only)', () => {
beforeEach(async () => {
// Authorized user from .cdsrc.json with PoetrySlamManager role
axios.defaults.auth = { username: 'peter', password: 'welcome' };
await test.data.reset();
await POST(`/odata/v4/poetryslamservice/createTestData`);
// Authentication for tests
axios.defaults.auth = { username: 'denise', password: 'welcome' };
});
it('should reject the reading of the poetry slams', async () => {
// Read all poetry slams; shall be rejected
await expect(
GET(`/odata/v4/poetryslammanagerapi/PoetrySlams`, {
params: { $select: `ID,status_code` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a poetry slam', async () => {
const poetrySlamToBeCreated = {
title: 'Poetry Slam 12',
description: 'Description Poetry Slam 12',
dateTime: new Date(),
visitorsFeeAmount: 9.95,
visitorsFeeCurrency_code: 'EUR'
};
// Create a new poetry slam; shall be rejected
await expect(
POST(`/odata/v4/poetryslammanagerapi/PoetrySlams`, poetrySlamToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the reading of visitors', async () => {
// Read all poetry slams; shall be rejected
await expect(
GET(`/odata/v4/poetryslammanagerapi/Visitors`, {
params: { $select: `ID,name` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a visitor', async () => {
const entryToBeCreated = {
name: 'Max Mustermann',
email: 'max@mustermann.de'
};
// Create a new poetry slam; shall be rejected
await expect(
POST(`/odata/v4/poetryslammanagerapi/Visitors`, entryToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the reading of visits', async () => {
// Read all poetry slams; shall be rejected
await expect(
GET(`/odata/v4/poetryslammanagerapi/Visits`, {
params: { $select: `ID,artists` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a visits', async () => {
const entryToBeCreated = {
parent_ID: '79ceab87-300d-4b66-8cc3-f82c679b77a8',
visitor_ID: '79ceab87-300d-4b66-8cc3-c82c679b7c12'
};
// Create a new poetry slam; shall be rejected as read-only
await expect(
POST(`/odata/v4/poetryslammanagerapi/Visits`, entryToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
});
// ----------------------------------------------------------------------------
// Tests authorizations for authorized user with role assignment PoetrySlamVisitor
// ----------------------------------------------------------------------------
describe('Authorizations of PoetrySlamManagerAPI with User Julie (role PoetrySlamVisitor)', () => {
beforeEach(async () => {
// Authorized user from .cdsrc.json with PoetrySlamManager role
axios.defaults.auth = { username: 'peter', password: 'welcome' };
await test.data.reset();
await POST(`/odata/v4/poetryslamservice/createTestData`);
// Authentication for tests
axios.defaults.auth = { username: 'julie', password: 'welcome' };
});
it('should reject to read data of poetry slams in status booked and published', async () => {
await expect(
GET(`/odata/v4/poetryslammanagerapi/PoetrySlams`, {
params: { $select: `ID,status_code` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a poetry slam', async () => {
const poetrySlamToBeCreated = {
number: '12',
title: 'Poetry Slam 12',
description: 'Description Poetry Slam 12',
dateTime: new Date(),
visitorsFeeAmount: 9.95,
visitorsFeeCurrency_code: 'EUR'
};
// Create a new poetry slam; shall be rejected
await expect(
POST(`/odata/v4/poetryslammanagerapi/PoetrySlams`, poetrySlamToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the reading of visitors', async () => {
await expect(
GET(`/odata/v4/poetryslammanagerapi/Visitors`, {
params: { $select: `ID,name` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a visitor', async () => {
const entryToBeCreated = {
name: 'Julie',
email: 'julie@pra.ondemand.com'
};
await expect(
POST(`/odata/v4/poetryslammanagerapi/Visitors`, entryToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject reading of visits', async () => {
await expect(
GET(`/odata/v4/poetryslammanagerapi/Visits`, {
params: { $select: `ID,artistIndicator` }
})
).to.rejectedWith(httpCodes.forbidden.toString());
});
it('should reject the creation of a visit', async () => {
const entryToBeCreated = {
parent_ID: '79ceab87-300d-4b66-8cc3-f82c679b77a8',
visitor_ID: '79ceab87-300d-4b66-8cc3-c82c679b7c12'
};
await expect(
POST(`/odata/v4/poetryslammanagerapi/Visits`, entryToBeCreated)
).to.rejectedWith(httpCodes.forbidden.toString());
});
});