@@ -6,104 +6,104 @@ const constants = require('../constants.js')
6
6
const app = require ( '../../../src/index.js' )
7
7
8
8
const params = { name : 'Test Organization' , id_quota : 100 }
9
- const secretariat_params = { name : 'MITRE Corporation' , id_quota : 100000 }
10
- const cna_params = { name : 'Adams, Nielsen and Hensley' , id_quota : 1309 }
9
+ const secretariatParams = { name : 'MITRE Corporation' , id_quota : 100000 }
10
+ const cnaParams = { name : 'Adams, Nielsen and Hensley' , id_quota : 1309 }
11
11
12
12
describe ( 'Testing org put endpoint' , ( ) => {
13
- context ( 'Positive Tests' , ( ) => {
14
- it ( 'Allows update made by a secretariat to itself' , async ( ) => {
15
- await chai . request ( app )
16
- . put ( '/api/org/mitre' )
17
- . set ( { ...constants . headers } )
18
- . query ( params )
19
- . send ( )
20
- . then ( ( res , err ) => {
21
- expect ( res ) . to . have . status ( 200 )
22
- expect ( res . body . updated . name ) . to . equal ( params . name )
23
- expect ( res . body . updated . policies . id_quota ) . to . equal ( params . id_quota )
24
- expect ( err ) . to . be . undefined
25
- } )
26
- await chai . request ( app )
27
- . put ( `/api/org/mitre` )
28
- . set ( { ...constants . headers } )
29
- . query ( secretariat_params )
30
- . send ( )
31
- . then ( ( res , err ) => {
32
- expect ( res ) . to . have . status ( 200 )
33
- expect ( res . body . updated . name ) . to . equal ( secretariat_params . name )
34
- expect ( res . body . updated . policies . id_quota ) . to . equal ( secretariat_params . id_quota )
35
- expect ( err ) . to . be . undefined
36
- } )
13
+ context ( 'Positive Tests' , ( ) => {
14
+ it ( 'Allows update made by a secretariat to itself' , async ( ) => {
15
+ await chai . request ( app )
16
+ . put ( '/api/org/mitre' )
17
+ . set ( { ...constants . headers } )
18
+ . query ( params )
19
+ . send ( )
20
+ . then ( ( res , err ) => {
21
+ expect ( res ) . to . have . status ( 200 )
22
+ expect ( res . body . updated . name ) . to . equal ( params . name )
23
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( params . id_quota )
24
+ expect ( err ) . to . be . undefined
37
25
} )
38
- it ( 'Allows update made by a secretariat to another org' , async ( ) => {
39
- await chai . request ( app )
40
- . put ( '/api/org/win_5' )
41
- . set ( { ...constants . headers } )
42
- . query ( params )
43
- . send ( )
44
- . then ( ( res , err ) => {
45
- expect ( res ) . to . have . status ( 200 )
46
- expect ( res . body . updated . name ) . to . equal ( params . name )
47
- expect ( res . body . updated . policies . id_quota ) . to . equal ( params . id_quota )
48
- expect ( err ) . to . be . undefined
49
- } )
50
- await chai . request ( app )
51
- . put ( '/api/org/win_5' )
52
- . set ( { ...constants . headers } )
53
- . query ( cna_params )
54
- . send ( )
55
- . then ( ( res , err ) => {
56
- expect ( res ) . to . have . status ( 200 )
57
- expect ( res . body . updated . name ) . to . equal ( cna_params . name )
58
- expect ( res . body . updated . policies . id_quota ) . to . equal ( cna_params . id_quota )
59
- expect ( err ) . to . be . undefined
60
- } )
26
+ await chai . request ( app )
27
+ . put ( '/api/org/mitre' )
28
+ . set ( { ...constants . headers } )
29
+ . query ( secretariatParams )
30
+ . send ( )
31
+ . then ( ( res , err ) => {
32
+ expect ( res ) . to . have . status ( 200 )
33
+ expect ( res . body . updated . name ) . to . equal ( secretariatParams . name )
34
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( secretariatParams . id_quota )
35
+ expect ( err ) . to . be . undefined
61
36
} )
62
- it ( 'Update made by non secretariat org to itself ONLY updates last_active field' , async ( ) => {
63
- let now = Date . now ( )
64
- await chai . request ( app )
65
- . put ( '/api/org/win_5' )
66
- . set ( { ...constants . nonSecretariatUserHeaders } )
67
- . query ( params )
68
- . send ( )
69
- . then ( ( res , err ) => {
70
- // Assert that that the last_active field was updated under 2 seconds ago
71
- let last_active = Date . parse ( res . body . updated . last_active )
72
- let diff = Math . abs ( now - last_active )
73
- let within_two_seconds = diff < 2000
74
- expect ( within_two_seconds ) . to . be . true
75
- // Assert no other fields were changed
76
- expect ( res ) . to . have . status ( 200 )
77
- expect ( res . body . updated . name ) . to . equal ( cna_params . name )
78
- expect ( res . body . updated . policies . id_quota ) . to . equal ( cna_params . id_quota )
79
- expect ( err ) . to . be . undefined
80
- } )
37
+ } )
38
+ it ( 'Allows update made by a secretariat to another org' , async ( ) => {
39
+ await chai . request ( app )
40
+ . put ( '/api/org/win_5' )
41
+ . set ( { ...constants . headers } )
42
+ . query ( params )
43
+ . send ( )
44
+ . then ( ( res , err ) => {
45
+ expect ( res ) . to . have . status ( 200 )
46
+ expect ( res . body . updated . name ) . to . equal ( params . name )
47
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( params . id_quota )
48
+ expect ( err ) . to . be . undefined
49
+ } )
50
+ await chai . request ( app )
51
+ . put ( '/api/org/win_5' )
52
+ . set ( { ...constants . headers } )
53
+ . query ( cnaParams )
54
+ . send ( )
55
+ . then ( ( res , err ) => {
56
+ expect ( res ) . to . have . status ( 200 )
57
+ expect ( res . body . updated . name ) . to . equal ( cnaParams . name )
58
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( cnaParams . id_quota )
59
+ expect ( err ) . to . be . undefined
81
60
} )
82
61
} )
83
- context ( 'Negative Tests' , ( ) => {
84
- it ( 'Fails update made by a non-secretariat org to a different org' , async ( ) => {
85
- await chai . request ( app )
86
- . put ( '/api/org/cause_8' )
87
- . set ( { ...constants . nonSecretariatUserHeaders } )
88
- . send ( )
89
- . then ( ( res , err ) => {
90
- expect ( res ) . to . have . status ( 401 )
91
- expect ( err ) . to . be . undefined
92
- expect ( res . body ) . to . haveOwnProperty ( 'error' )
93
- expect ( res . body . error ) . to . equal ( 'UNAUTHORIZED' )
94
- } )
62
+ it ( 'Update made by non secretariat org to itself ONLY updates last_active field' , async ( ) => {
63
+ const now = Date . now ( )
64
+ await chai . request ( app )
65
+ . put ( '/api/org/win_5' )
66
+ . set ( { ...constants . nonSecretariatUserHeaders } )
67
+ . query ( params )
68
+ . send ( )
69
+ . then ( ( res , err ) => {
70
+ // Assert that that the last_active field was updated under 2 seconds ago
71
+ const lastActive = Date . parse ( res . body . updated . last_active )
72
+ const diff = Math . abs ( now - lastActive )
73
+ const withinTwoSeconds = diff < 2000
74
+ expect ( withinTwoSeconds ) . to . be . true
75
+ // Assert no other fields were changed
76
+ expect ( res ) . to . have . status ( 200 )
77
+ expect ( res . body . updated . name ) . to . equal ( cnaParams . name )
78
+ expect ( res . body . updated . policies . id_quota ) . to . equal ( cnaParams . id_quota )
79
+ expect ( err ) . to . be . undefined
95
80
} )
96
- it ( 'Fails update made by a non-secretariat org to a secretariat' , async ( ) => {
97
- await chai . request ( app )
98
- . put ( '/api/org/mitre' )
99
- . set ( { ...constants . nonSecretariatUserHeaders } )
100
- . send ( )
101
- . then ( ( res , err ) => {
102
- expect ( res ) . to . have . status ( 401 )
103
- expect ( err ) . to . be . undefined
104
- expect ( res . body ) . to . haveOwnProperty ( 'error' )
105
- expect ( res . body . error ) . to . equal ( 'UNAUTHORIZED' )
106
- } )
81
+ } )
82
+ } )
83
+ context ( 'Negative Tests' , ( ) => {
84
+ it ( 'Fails update made by a non-secretariat org to a different org' , async ( ) => {
85
+ await chai . request ( app )
86
+ . put ( '/api/org/cause_8' )
87
+ . set ( { ...constants . nonSecretariatUserHeaders } )
88
+ . send ( )
89
+ . then ( ( res , err ) => {
90
+ expect ( res ) . to . have . status ( 401 )
91
+ expect ( err ) . to . be . undefined
92
+ expect ( res . body ) . to . haveOwnProperty ( 'error' )
93
+ expect ( res . body . error ) . to . equal ( 'UNAUTHORIZED' )
94
+ } )
95
+ } )
96
+ it ( 'Fails update made by a non-secretariat org to a secretariat' , async ( ) => {
97
+ await chai . request ( app )
98
+ . put ( '/api/org/mitre' )
99
+ . set ( { ...constants . nonSecretariatUserHeaders } )
100
+ . send ( )
101
+ . then ( ( res , err ) => {
102
+ expect ( res ) . to . have . status ( 401 )
103
+ expect ( err ) . to . be . undefined
104
+ expect ( res . body ) . to . haveOwnProperty ( 'error' )
105
+ expect ( res . body . error ) . to . equal ( 'UNAUTHORIZED' )
107
106
} )
108
107
} )
109
- } )
108
+ } )
109
+ } )
0 commit comments