@@ -10,7 +10,7 @@ chai.use(sinonChai)
1010chai . should ( )
1111
1212const AccountTemplate = require ( '../../lib/models/account-template' )
13-
13+ const UserAccount = require ( '../../lib/models/user-account' )
1414const templatePath = path . join ( __dirname , '../../default-templates/new-account' )
1515const accountPath = path . join ( __dirname , '../resources/new-account' )
1616
@@ -62,4 +62,71 @@ describe('AccountTemplate', () => {
6262 } )
6363 } )
6464 } )
65+
66+ describe ( 'templateSubtitutionsFor()' , ( ) => {
67+ it ( 'should not update the webid' , ( ) => {
68+ const userAccount = new UserAccount ( {
69+ webId : 'https://alice.example.com/#me' ,
70+ 71+ name : 'Alice Q.'
72+ } )
73+
74+ const substitutions = AccountTemplate . templateSubstitutionsFor ( userAccount )
75+
76+ expect ( substitutions . webId ) . to . equal ( '/#me' )
77+ } )
78+
79+ it ( 'should not update the nested webid' , ( ) => {
80+ const userAccount = new UserAccount ( {
81+ webId : 'https://alice.example.com/alice/#me' ,
82+ 83+ name : 'Alice Q.'
84+ } )
85+
86+ const substitutions = AccountTemplate . templateSubstitutionsFor ( userAccount )
87+
88+ expect ( substitutions . webId ) . to . equal ( '/alice/#me' )
89+ } )
90+
91+ it ( 'should update the webid' , ( ) => {
92+ const userAccount = new UserAccount ( {
93+ webId : 'http://localhost:8443/alice/#me' ,
94+ 95+ name : 'Alice Q.'
96+ } )
97+
98+ const substitutions = AccountTemplate . templateSubstitutionsFor ( userAccount )
99+
100+ expect ( substitutions . webId ) . to . equal ( '/alice/#me' )
101+ } )
102+ } )
103+
104+ describe ( 'creating account where webId does match server Uri?' , ( ) => {
105+ it ( 'should have a relative uri for the base path rather than a complete uri' , ( ) => {
106+ const userAccount = new UserAccount ( {
107+ webId : 'http://localhost:8443/alice/#me' ,
108+ 109+ name : 'Alice Q.'
110+ } )
111+
112+ const substitutions = AccountTemplate . templateSubstitutionsFor ( userAccount )
113+ const template = new AccountTemplate ( { substitutions } )
114+ return AccountTemplate . copyTemplateDir ( templatePath , accountPath )
115+ . then ( ( ) => {
116+ return template . processAccount ( accountPath )
117+ } ) . then ( ( ) => {
118+ const profile = fs . readFileSync ( path . join ( accountPath , '/profile/card$.ttl' ) , 'utf8' )
119+ expect ( profile ) . to . include ( '"Alice Q."' )
120+ expect ( profile ) . to . include ( 'solid:oidcIssuer' )
121+ // why does this need to be included?
122+ // with the current configuration, 'host' for
123+ // ldp is not set, therefore solid:oidcIssuer is empty
124+ // expect(profile).to.include('<https://example.com>')
125+
126+ const rootAcl = fs . readFileSync ( path . join ( accountPath , '.acl' ) , 'utf8' )
127+ expect ( rootAcl ) . to . include ( '<mailto:alice@' )
128+ expect ( rootAcl ) . to . include ( '</alice/#me>' )
129+ } )
130+ } )
131+ } )
65132} )
0 commit comments