Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redoing work in the first branch to see if it deploys properly #1541

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion shnippet.config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"rootDirectory": "./site/testsuites",
"rootDirectories": [
"./site/testsuites",
"./site/docs/tbdex/test",
"./site/docs/web5/test"
],
"outputDirectory": "./site/snippets",
"fileExtensions": [".js", ".ts", ".kt", ".gradle", ".xml", ".bash", ".swift"],
"exclude": ["pfiOverviewReadOfferingsJs", "pfiOverviewWriteJs", "pfiOverviewWriteOfferingsJs"],
Expand Down
39 changes: 36 additions & 3 deletions shnippet/src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,36 @@ function clearOutputDirectory(outputDirectory) {
}
}

function findTestDirectories(baseDir) {
let testDirectories = [];

function traverseDirectory(currentDir) {
const files = fs.readdirSync(currentDir);
for (const file of files) {
const filePath = path.join(currentDir, file);
const stats = fs.statSync(filePath);

if (stats.isDirectory()) {
if (file === "test") {
testDirectories.push(filePath);
} else {
traverseDirectory(filePath);
}
}
}
}

traverseDirectory(baseDir);
return testDirectories;
}

function main() {
const args = process.argv.slice(2);
const configPath = findConfigFile();
const configDir = path.dirname(configPath);
let config = require(configPath);

config.rootDirectory = path.resolve(configDir, config.rootDirectory);
// Resolve paths for output directory
config.outputDirectory = path.resolve(configDir, config.outputDirectory);

// Check for "clear" argument
Expand Down Expand Up @@ -62,8 +85,18 @@ function main() {
process.exit(1);
}

const extractor = new SnippetExtractor(config);
extractor.extractSnippets();
// Process each root directory or traverse dynamically
let directoriesToProcess = config.rootDirectories
.map((rootDir) => path.resolve(configDir, rootDir))
.reduce((acc, dir) => {
return acc.concat(findTestDirectories(dir));
}, []);

directoriesToProcess.forEach((directory) => {
config.rootDirectory = directory; // Set the current root directory
const extractor = new SnippetExtractor(config);
extractor.extractSnippets();
});
}

main();
File renamed without changes.
10 changes: 5 additions & 5 deletions site/docs/docs-index.js → site/docs/common/docs-index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import HeroCard from '@site/src/components/HeroCard';
import ExploreCard from '../src/components/ExploreCard';
import Community from '../src/components/Community';
import ExploreCard from '../../src/components/ExploreCard';
import Community from '../../src/components/Community';
import Head from '@docusaurus/Head';

function DocsIndex() {
Expand All @@ -14,8 +14,9 @@ function DocsIndex() {
Give your customers control of their identity, data, and finances.
</h1>
<p className="mb-8">
Our toolkits bring decentralized identity, messaging, and data storage to your applications.
They let developers focus on creating delightful user experiences, while returning ownership to individuals.
Our toolkits bring decentralized identity, messaging, and data storage
to your applications. They let developers focus on creating delightful
user experiences, while returning ownership to individuals.
</p>
<div className="grid grid-cols-1 desktop:grid-cols-2 gap-4">
<HeroCard
Expand All @@ -35,7 +36,6 @@ function DocsIndex() {
imgSrc="/img/money-msg-blue-purple.svg"
imgClass="w-36 flip"
themeColor="cyan"

/>
</div>

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Rfq, Quote, Parser } from '@tbdex/http-server';
import { DevTools } from '@tbdex/http-client';
import { DidDht } from '@web5/dids';
import { OfferingsApiProvider } from './offeringsApiProvider'
import { ExchangesApiProvider } from './exchangesApiProvider'
import { MockDataProvider } from '../../utils/mockDataProvider'
import { OfferingsApiProvider } from './offeringsApiProvider';
import { ExchangesApiProvider } from './exchangesApiProvider';
import { MockDataProvider } from '../../../test-utils/mockDataProvider';
import { vi, test, expect, describe, beforeAll } from 'vitest';

let pfiDid;
Expand All @@ -18,45 +18,47 @@ describe('PFI: Quotes', () => {
beforeAll(async () => {
// Set up providers and DID
pfiDid = await DidDht.create({
options:{
options: {
publish: true,
services: [{
services: [
{
id: 'pfi',
type: 'PFI',
serviceEndpoint: 'https://example.com/'
}]
}
serviceEndpoint: 'https://example.com/',
},
],
},
});

senderDid = await DidDht.create({
options: { publish: true }
})
options: { publish: true },
});

offeringsApiProvider = new OfferingsApiProvider(pfiDid);
exchangesApiProvider = new ExchangesApiProvider();

// Configure Mocks

message = await DevTools.createRfq({
sender: senderDid,
receiver: pfiDid
receiver: pfiDid,
});
await message.sign(senderDid);

mockOffering = DevTools.createOffering({
from: pfiDid.uri,
offeringData: DevTools.createOfferingData()
})
offeringData: DevTools.createOfferingData(),
});
await mockOffering.sign(pfiDid);


message.offeringId = mockOffering.id;
offeringsApiProvider.setOffering(mockOffering);


dataProvider.setupInsert("exchange", "", () => { return });
dataProvider.setupInsert('exchange', '', () => {
return;
});
});

test('PFI creates offering', async () => {
// :snippet-start: pfiWriteOfferingJs
// Write the message to your exchanges database
Expand All @@ -65,17 +67,17 @@ describe('PFI: Quotes', () => {
messagekind: message.kind,
messageid: message.id,
subject: message.subject,
message: await Parser.parseMessage(message)
message: await Parser.parseMessage(message),
});

//highlight-start
const offering = await offeringsApiProvider.getOffering(message.offeringId);
//highlight-end
// :snippet-end:
})
});

test('PFI creates and signs quote', async () => {
const offering = mockOffering
const offering = mockOffering;

// :snippet-start: pfiCreateQuoteJs
// Set the Quote's expiration date for 10 days from now
Expand All @@ -87,39 +89,38 @@ describe('PFI: Quotes', () => {
from: pfiDid.uri,
to: message.from,
exchangeId: message.exchangeId,
protocol: '1.0'
protocol: '1.0',
},
data: {
expiresAt: quoteExpiration.toLocaleDateString('en-us'),
payin: {
currencyCode: offering.data.payin.currencyCode,
amount: '0.01',
fee: '0.0001',
paymentInstruction : {
paymentInstruction: {
link: 'https://example.com/paymentInstructions',
instruction: 'Detailed payment instructions'
}
instruction: 'Detailed payment instructions',
},
},
payout: {
currencyCode: offering.data.payout.currencyCode,
amount: '1000.00',
paymentInstruction : {
paymentInstruction: {
link: 'https://example.com/paymentInstructions',
instruction: 'Detailed payout instructions'
}
}
}
instruction: 'Detailed payout instructions',
},
},
},
});
// :snippet-end:

exchangesApiProvider.setWrite();

// :snippet-start: pfiSignQuoteJs
await quote.sign(pfiDid);
exchangesApiProvider.write(quote);
// :snippet-end:
const signature = await quote.verifySignature();
expect(signature).toBeDefined();
})

})
});
});
22 changes: 22 additions & 0 deletions site/docs/tbdex/test/pfi/exchangesApiProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { MockExchangesApiProvider } from '../../../test-utils/mockExchangesApiProvider';

export class ExchangesApiProvider extends MockExchangesApiProvider {
// :snippet-start: pfiOverviewWriteJs
async write(message, replyTo) {
await this.dataProvider.insert('exchange', {
exchangeid: message.exchangeId,
messagekind: message.kind,
messageid: message.id,
subject: message.subject,
message: JSON.stringify(message),
});

if (replyTo != null) {
await this.dataProvider.insert('callbacks', {
exchangeId: message.exchangeId,
uri: replyTo,
});
}
}
// :snippet-end:
}
41 changes: 41 additions & 0 deletions site/docs/tbdex/test/pfi/offeringsApiProvider.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { MockOfferingsApiProvider } from '../../../test-utils/mockOfferingsApiProvider';
import { Parser } from '@tbdex/http-server';

export class OfferingsApiProvider extends MockOfferingsApiProvider {
constructor(pfiDid) {
super();
this.pfiDid = pfiDid;
}

// :snippet-start: pfiOverviewReadOfferingsJs
async getOffering(id) {
return this.dataProvider.get('offering', id).then(async (result) => {
if (result) {
return await Parser.parseResource(result);
}
});
}

async getOfferings() {
return this.dataProvider.query('offering', '*').then((results) => {
const offerings = [];

for (let result of results) {
const offering = Parser.rawToResourceModel(result);
offerings.push(offering);
}

return offerings;
});
}

async setOffering(offering) {
await this.dataProvider.insert('offering', {
offeringid: offering.metadata.id,
payoutcurrency: offering.data.payout.currencyCode,
payincurrency: offering.data.payin.currencyCode,
offering: Parser.rawToResourceModel(offering),
});
}
// :snippet-end:
}
Loading
Loading