Skip to content

Commit 4119a73

Browse files
integration test, three cases
1 parent c7fbe57 commit 4119a73

File tree

4 files changed

+164
-1
lines changed

4 files changed

+164
-1
lines changed

lib/payment-pointer-discovery.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,11 @@ function paymentPointerDocument () {
6969
res.json({ fail: 'Add triple', subject: `<${webid.value}>`, predicate: `<${pp.value}>`, object: '$alice.example' })
7070
}
7171
if (paymentPointer.value.startsWith('$')) {
72-
paymentPointer.value = `https://${paymentPointer.value.substring(1)}`
72+
let suffix = ''
73+
if (paymentPointer.value.indexOf('/') === -1) {
74+
suffix = '/.well-known/pay'
75+
}
76+
paymentPointer.value = `https://${paymentPointer.value.substring(1)}${suffix}`
7377
}
7478
res.redirect(paymentPointer.value)
7579
} catch (e) {
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/* eslint-disable no-unused-expressions */
2+
3+
const Solid = require('../../index')
4+
const path = require('path')
5+
const { cleanDir } = require('../utils')
6+
const supertest = require('supertest')
7+
const expect = require('chai').expect
8+
9+
describe('API', () => {
10+
const configPath = path.join(__dirname, '../resources/config')
11+
12+
const serverConfig = {
13+
sslKey: path.join(__dirname, '../keys/key.pem'),
14+
sslCert: path.join(__dirname, '../keys/cert.pem'),
15+
auth: 'oidc',
16+
dataBrowser: false,
17+
webid: true,
18+
multiuser: false,
19+
configPath
20+
}
21+
22+
function startServer (pod, port) {
23+
return new Promise((resolve) => {
24+
pod.listen(port, () => { resolve() })
25+
})
26+
}
27+
28+
describe('Payment Pointer Alice', () => {
29+
let alice
30+
const aliceServerUri = 'https://localhost:5000'
31+
const aliceDbPath = path.join(__dirname,
32+
'../resources/accounts-scenario/alice/db')
33+
const aliceRootPath = path.join(__dirname, '../resources/accounts-scenario/alice')
34+
35+
const alicePod = Solid.createServer(
36+
Object.assign({
37+
root: aliceRootPath,
38+
serverUri: aliceServerUri,
39+
dbPath: aliceDbPath
40+
}, serverConfig)
41+
)
42+
43+
before(() => {
44+
return Promise.all([
45+
startServer(alicePod, 5000)
46+
]).then(() => {
47+
alice = supertest(aliceServerUri)
48+
})
49+
})
50+
51+
after(() => {
52+
alicePod.close()
53+
cleanDir(aliceRootPath)
54+
})
55+
56+
describe('GET Payment Pointer document', () => {
57+
it('should show instructions to add a triple', (done) => {
58+
alice.get('/.well-known/pay')
59+
.expect(200)
60+
.expect('content-type', /application\/json/)
61+
.end(function (err, req) {
62+
if (err) {
63+
done(err)
64+
} else {
65+
expect(req.body).deep.equal({
66+
fail: 'Add triple',
67+
subject: '<https://localhost:5000/profile/card#me>',
68+
predicate: '<http://paymentpointers.org/ns#PaymentPointer>',
69+
object: '$alice.example'
70+
})
71+
done()
72+
}
73+
})
74+
})
75+
})
76+
})
77+
78+
describe('Payment Pointer Bob', () => {
79+
let bob
80+
const bobServerUri = 'https://localhost:5001'
81+
const bobDbPath = path.join(__dirname,
82+
'../resources/accounts-scenario/bob/db')
83+
const bobRootPath = path.join(__dirname, '../resources/accounts-scenario/bob')
84+
const bobPod = Solid.createServer(
85+
Object.assign({
86+
root: bobRootPath,
87+
serverUri: bobServerUri,
88+
dbPath: bobDbPath
89+
}, serverConfig)
90+
)
91+
92+
before(() => {
93+
return Promise.all([
94+
startServer(bobPod, 5001)
95+
]).then(() => {
96+
bob = supertest(bobServerUri)
97+
})
98+
})
99+
100+
after(() => {
101+
bobPod.close()
102+
cleanDir(bobRootPath)
103+
})
104+
105+
describe('GET Payment Pointer document', () => {
106+
it('should redirect to example.com', (done) => {
107+
bob.get('/.well-known/pay')
108+
.expect('location', 'https://bob.com/.well-known/pay')
109+
.expect(302, done)
110+
})
111+
})
112+
})
113+
114+
describe('Payment Pointer Charlie', () => {
115+
let charlie
116+
const charlieServerUri = 'https://localhost:5002'
117+
const charlieDbPath = path.join(__dirname,
118+
'../resources/accounts-scenario/charlie/db')
119+
const charlieRootPath = path.join(__dirname, '../resources/accounts-scenario/charlie')
120+
const charliePod = Solid.createServer(
121+
Object.assign({
122+
root: charlieRootPath,
123+
serverUri: charlieServerUri,
124+
dbPath: charlieDbPath
125+
}, serverConfig)
126+
)
127+
128+
before(() => {
129+
return Promise.all([
130+
startServer(charliePod, 5002)
131+
]).then(() => {
132+
charlie = supertest(charlieServerUri)
133+
})
134+
})
135+
136+
after(() => {
137+
charliePod.close()
138+
cleanDir(charlieRootPath)
139+
})
140+
141+
describe('GET Payment Pointer document', () => {
142+
it('should redirect to example.com/charlie', (done) => {
143+
charlie.get('/.well-known/pay')
144+
.expect('location', 'https://service.com/charlie')
145+
.expect(302, done)
146+
})
147+
})
148+
})
149+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@prefix : <#>.
2+
@prefix pp: <http://paymentpointers.org/ns#>.
3+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4+
5+
:me pp:PaymentPointer "$bob.com"^^xsd:string .
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@prefix : <#>.
2+
@prefix pp: <http://paymentpointers.org/ns#>.
3+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
4+
5+
:me pp:PaymentPointer "$service.com/charlie"^^xsd:string .

0 commit comments

Comments
 (0)