Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Update fan club example (#14)
Browse files Browse the repository at this point in the history
* add tbd example json

* put fan-club-example tests on newer node

---------

Co-authored-by: finn <[email protected]>
  • Loading branch information
nitro-neal and finn-block authored Jun 14, 2024
1 parent 43544c6 commit ac489ea
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 24 deletions.
34 changes: 20 additions & 14 deletions .github/generate-test-steps.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
const { readdirSync, readFileSync, existsSync, statSync } = require('node:fs');

const defaultSteps = {
const defaults = {
javascript: {
preTest: ["npm install"],
test: ["npm test"],
tests: {
pre: ["npm install"],
command: ["npm test"]
},
},
kotlin: {
test: ["./gradlew connectedCheck"],
tests: {
command: ["./gradlew connectedCheck"],
}
}
}

Expand All @@ -33,30 +37,32 @@ for (const language of readdirSync('.')) {

const config = JSON.parse(readFileSync(directory + '/.tbd-example.json', 'utf8'));

var preTestCommands = defaultSteps[language].preTest
const entry = {
name: config.name || example,
directory: directory,
tests: {},
misc: config.misc || {},
};

var preTestCommands = defaults[language].tests ? defaults[language].tests.pre : null;
if (config.tests && config.tests.pre) {
preTestCommands = config.tests.pre;
}
if (preTestCommands) {
preTestCommands = formatCommands(preTestCommands);
entry.tests.pre = formatCommands(preTestCommands);
}

var testCommands = defaultSteps[language].test
var testCommands = defaults[language].tests ? defaults[language].tests.command : null;
if (config.tests && config.tests.command) {
testCommands = [config.tests.command];
} else if (config.tests && config.tests.commands) {
testCommands = config.tests.commands;
}
if (testCommands) {
testCommands = formatCommands(testCommands);
entry.tests.command = formatCommands(testCommands);
}

examples.push({
name: config.name || example,
directory: directory,
preTestCommands: preTestCommands,
testCommands: testCommands
});
examples.push(entry);
}

if (examples.length > 0) {
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ jobs:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v4.0.2
with:
node-version: '20.4.0'
node-version: ${{ matrix.example.misc.node-version || '20.4.0' }}
- name: test setup
run: ${{ matrix.example.preTestCommands }}
run: ${{ matrix.example.tests.pre }}
working-directory: ${{ matrix.example.directory }}
if: matrix.example.preTestCommands != null
if: matrix.example.tests.pre != null
- name: test
run: ${{ matrix.example.testCommands }}
run: ${{ matrix.example.tests.command }}
working-directory: ${{ matrix.example.directory }}

kotlin:
Expand Down Expand Up @@ -69,12 +69,12 @@ jobs:
- name: Setup Android SDK
uses: android-actions/setup-android@00854ea68c109d98c75d956347303bf7c45b0277 # v3.2.1
- name: test setup
run: ${{ matrix.example.preTestCommands }}
run: ${{ matrix.example.tests.pre }}
working-directory: ${{ matrix.example.directory }}
if: matrix.example.preTestCommands != null
if: matrix.example.test.pre != null
- name: test in android emulator
uses: reactivecircus/android-emulator-runner@77986be26589807b8ebab3fde7bbf5c60dabec32 # v2.31.0
with:
api-level: 29
script: ${{ matrix.example.testCommands }}
script: ${{ matrix.example.tests.command }}
working-directory: ${{ matrix.example.directory }}
9 changes: 9 additions & 0 deletions javascript/fan-club-credential/.tbd-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "Fan Club Credential",
"tests": {
"command": "node index.js"
},
"misc": {
"node-version": "v22.2.0"
}
}
6 changes: 3 additions & 3 deletions javascript/fan-club-credential/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ try {
const presentationResult = PresentationExchange.createPresentationFromCredentials({ vcJwts: [signedVcJwt], presentationDefinition: presentationDefinition });
console.log('\nPresentation Result: ' + JSON.stringify(presentationResult));


/**
* Storing a self signed VC in a DWN
*/
Expand All @@ -104,11 +105,10 @@ const userAgent = await Web5UserAgent.create();
if (await userAgent.firstLaunch()) {
// The vault has not been initialized yet.
await userAgent.initialize({ password: 'insecure-static-phrase' });
} else {
// The vault is already initialized, so just unlock/start it.
await userAgent.start({ password: 'insecure-static-phrase' });
}

await userAgent.start({ password: 'insecure-static-phrase' });

// Import Alice's DID as an agent-managed Identity.
const identity = await userAgent.identity.import({
portableIdentity: {
Expand Down

0 comments on commit ac489ea

Please sign in to comment.