Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mv_getusergroups.test.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Testing mv_getusergroups macro
4 @details The current-user and unknown-user paths run with VARINITCHK=ERROR.
5 A current user may legitimately have no memberships.
6
7 <h4> SAS Macros </h4>
8 @li mf_getuser.sas
9 @li mf_getuniquelibref.sas
10 @li mp_assert.sas
11 @li mp_assertdsobs.sas
12 @li mp_assertmodel.sas
13 @li mp_assertscope.sas
14 @li mv_getusergroups.sas
15
16**/
17
18/* The JSON engine creates globals named for its allocated libref. */
19%macro usergroups_scope_compare(desc=,json_libref=);
20 %local json_globals;
21 %let json_globals=;
22 proc sql noprint;
23 select distinct name into :json_globals separated by ' '
24 from dictionary.macros
25 where scope='GLOBAL'
26 and upcase(scan(strip(name),1,'_'))=upcase(symget('json_libref'))
27 and countw(strip(name),'_')=2
28 and prxmatch('/^JAD(P\d+LEN|PNUM|VLEN)$/i',scan(strip(name),2,'_'));
29 quit;
30 %mp_assertscope(COMPARE,ignorelist=&json_globals
31 ,desc=&desc,outds=work.test_results)
32%mend usergroups_scope_compare;
33
34/* Define the expected model independently of the macro output. */
35data work.usergroupsmodel;
36 length version 8 id $256 implicit 8 name $256 providerId $32;
37 call missing(of _all_);
38 stop;
39run;
40
41/* Occupy the first available ref so the tested macro must choose another. */
42%let usergroups_reserved=%mf_getuniquelibref();
43libname &usergroups_reserved (work);
44%let usergroups_jsonref=%mf_getuniquelibref();
45%mp_assertscope(SNAPSHOT)
46%mv_getusergroups(user=%mf_getuser(), outds=work.usergroups)
47%mp_assert(iftrue=(&SYS_PROCHTTP_STATUS_CODE=200),
48 desc=Current-user request returns HTTP 200,
49 outds=work.test_results
50)
51%mp_assert(iftrue=(&syscc=0),
52 desc=Current-user call succeeds with VARINITCHK ERROR,
53 outds=work.test_results
54)
55%usergroups_scope_compare(desc=mv_getusergroups does not leak scope,
56 json_libref=&usergroups_jsonref)
57libname &usergroups_reserved clear;
58
59%mp_assert(
60 iftrue=(%sysfunc(exist(work.usergroups))=1),
61 desc=Check the user groups dataset was created,
62 outds=work.test_results
63)
64
65/* Check the complete output model, including the absence of extra columns. */
66%mp_assertmodel(work.usergroups,base=work.usergroupsmodel,
67 desc=The listing matches the documented model,
68 outds=work.test_results
69)
70proc sql noprint;
71 select count(*) into :missing_group_names trimmed
72 from work.usergroups
73 where missing(name);
74quit;
75%mp_assert(
76 iftrue=(&missing_group_names=0),
77 desc=All listed groups have a name,
78 outds=work.test_results
79)
80
81/* a user the server does not know - the macro answers with the documented
82 columns and zero rows rather than failing on the 404 body */
83%mp_assertscope(SNAPSHOT)
84%mv_getusergroups(user=no_such_user_sasjs_core, outds=work.unknown)
85%mp_assert(iftrue=(&syscc=0),
86 desc=Unknown-user call succeeds with VARINITCHK ERROR,
87 outds=work.test_results
88)
89%mp_assertscope(COMPARE,
90 desc=mv_getusergroups does not leak scope on an unknown user,
91 outds=work.test_results
92)
93%mp_assert(iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
94 desc=Unknown-user request returns HTTP 404,
95 outds=work.test_results
96)
97%mp_assertdsobs(work.unknown,
98 desc=Check an unknown user returns no rows,
99 test=EMPTY,
100 outds=work.test_results
101)
102%mp_assertmodel(work.unknown,base=work.usergroupsmodel,
103 desc=An unknown user answers the documented model,
104 outds=work.test_results
105)