|
| 1 | +import { URL } from 'url'; |
| 2 | +import { createServer, Server } from 'http'; |
1 | 3 | import { SolidLogic } from 'solid-logic';
|
2 | 4 | import { generateTestFolder, getSolidLogicInstance, WEBID_ALICE, WEBID_BOB } from '../helpers/env';
|
3 |
| -import { responseCodeGroup } from '../helpers/util'; |
| 5 | +// import { responseCodeGroup } from '../helpers/util'; |
| 6 | + |
| 7 | +class Oracle { |
| 8 | + paid = [] |
| 9 | + calls: URL[] |
| 10 | + server: Server |
| 11 | + constructor() { |
| 12 | + this.calls = [] |
| 13 | + this.server = createServer((req, res) => { |
| 14 | + const url = new URL(`http://oracle${req.url}`); |
| 15 | + console.log('oracle hit!', url.searchParams.get('agent'), url.searchParams.get('resource')) |
| 16 | + this.calls.push(url) |
| 17 | + if (this.paid.indexOf(url.searchParams.get('resource')) === -1) { |
| 18 | + res.end(JSON.stringify({ |
| 19 | + payHeaders: [ |
| 20 | + 'interledger-stream some.destination.account. Some+Shared+Secret+in+Base64==' |
| 21 | + ] |
| 22 | + })) |
| 23 | + } else { |
| 24 | + res.end('OK') |
| 25 | + } |
| 26 | + }) |
| 27 | + } |
| 28 | +} |
4 | 29 |
|
5 | 30 | function makeBody(accessToModes: string, defaultModes: string, target: string) {
|
6 | 31 | let str = [
|
@@ -36,9 +61,16 @@ function makeBody(accessToModes: string, defaultModes: string, target: string) {
|
36 | 61 | describe('Read-Paying', () => {
|
37 | 62 | let solidLogicAlice: SolidLogic;
|
38 | 63 | let solidLogicBob: SolidLogic;
|
| 64 | + let oracle: Oracle; |
39 | 65 | beforeAll(async () => {
|
40 | 66 | solidLogicAlice = await getSolidLogicInstance('ALICE')
|
41 | 67 | solidLogicBob = await getSolidLogicInstance('BOB')
|
| 68 | + oracle = new Oracle(); |
| 69 | + await oracle.server.listen(8402); |
| 70 | + console.log('oracle listening') |
| 71 | + }); |
| 72 | + afterAll(async () => { |
| 73 | + oracle.server.close(); |
42 | 74 | });
|
43 | 75 |
|
44 | 76 | const { testFolderUrl } = generateTestFolder('ALICE');
|
@@ -73,5 +105,7 @@ describe('Read-Paying', () => {
|
73 | 105 | });
|
74 | 106 | const result = await solidLogicBob.fetch(resourceUrl)
|
75 | 107 | expect(result.status).toEqual(402);
|
| 108 | + const payHeader = result.headers.get('Pay'); |
| 109 | + expect(payHeader).toEqual('interledger-stream some.destination.account. Some+Shared+Secret+in+Base64=='); |
76 | 110 | });
|
77 | 111 | });
|
0 commit comments