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