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

feat: implement renderer 2024 provider #177

Merged
merged 47 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
61ed51f
feat: add compute hash utils
ldhyen99 Apr 26, 2024
034f537
feat: add prefix in compute hash function
ldhyen99 May 2, 2024
ca1e3f4
feat: create plugin that contain hash
ldhyen99 May 3, 2024
14fc4b8
test: add unit test for compute hash
ldhyen99 May 3, 2024
a49ee9c
feat: implement renderer 2024 provider
ducpm511 May 3, 2024
f02873d
feat: add plugin to agent.yml
ldhyen99 May 3, 2024
b572e1d
refactor: delete compute hash function in tools package
ldhyen99 May 3, 2024
fdac6c1
chore: update ts config file
ldhyen99 May 3, 2024
ec3746f
Merge branch 'feat/add_compute_hash_utils' into renderer2024
ducpm511 May 6, 2024
9a033de
feat: implement new UI for renderer on demo explorer
ducpm511 May 7, 2024
713e011
Merge branch 'next' into renderer2024
ducpm511 May 7, 2024
5afd5ab
feat: updated unit tests
ducpm511 May 7, 2024
caef6c5
feat: handled error
ducpm511 May 7, 2024
4001ef1
Merge branch 'next' into renderer2024
ducpm511 May 14, 2024
d3581cc
feat: updated according to feedback
ducpm511 May 14, 2024
2f05cca
feat: updated renderer to be able to use extractRendererMethod function
ducpm511 May 14, 2024
85b33a0
refactor: clean up renderer
ducpm511 May 17, 2024
7b4ac12
Merge branch 'next' into renderer2024
ducpm511 May 17, 2024
65b9a24
refactor: adding missing template
ducpm511 May 17, 2024
c55545e
Merge branch 'next' into renderer2024
ducpm511 May 17, 2024
fec182d
refactor: renamed provider name; replace context url
ducpm511 May 17, 2024
8891f63
Merge branch 'next' into renderer2024
ducpm511 May 17, 2024
edcfcc0
refactor: updated provider according to computeHash function changes
ducpm511 May 17, 2024
2e6ec77
refactor: implement to support mediaQuery and refactor code
ducpm511 May 21, 2024
360f777
refactor: enhance the performance by set documentLoader
namhoang1604 May 21, 2024
ac6094c
refactor: updated response type and rename test file
ducpm511 May 21, 2024
e3e78cc
refactor: updated default contexts for renderer
ducpm511 May 21, 2024
ac71f0b
fix: display rendered template on UI and return renderedTemplate fiel…
ldhyen99 May 24, 2024
607a359
refactor: update render template 2024
ducpm511 May 29, 2024
78445c2
feat: update demo-explorer to support render template 2024
ducpm511 Jun 4, 2024
e035b72
Merge branch 'next' into renderer2024
ducpm511 Jun 4, 2024
ab74283
chore: updated unit test corresponding to changes of render provider
ducpm511 Jun 6, 2024
d3bcc29
chore: fix renderer to address unit test
ducpm511 Jun 6, 2024
2080de3
Merge branch 'next' into renderer2024
ducpm511 Jun 6, 2024
ebca386
Merge branch 'next' into renderer2024
ducpm511 Jun 7, 2024
cce6eb6
chore: added more test case to increase the coverage
ducpm511 Jun 7, 2024
1d602ad
chore: added more unit test cases
ducpm511 Jun 7, 2024
5fbca74
Merge branch 'next' into renderer2024
ducpm511 Jun 7, 2024
46f7bcf
chore: reduced uncovered count for statement
ducpm511 Jun 10, 2024
c370dea
Merge branch 'next' into renderer2024
namhoang1604 Jun 12, 2024
a65aae1
chore: removed duplicate test case
ducpm511 Jun 12, 2024
d4e31b1
refactor: use the inline template if failed to fetch it from url.
ducpm511 Jun 12, 2024
75c4d42
fix: removed duplicate test case and implement mock fetch to simulate…
ducpm511 Jun 12, 2024
aa46d60
fix: wrong expected result
ducpm511 Jun 13, 2024
50c45c4
chore: removed meanless comment
ducpm511 Jun 13, 2024
ed4ec10
refactor: enhance the render template 2024
namhoang1604 Jun 13, 2024
25ff963
test: adjust to update the unit test of renderer plugin
namhoang1604 Jun 13, 2024
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
54 changes: 54 additions & 0 deletions packages/renderer/__tests__/providers/render-template-2024.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RenderTemplate2024 } from '../../src/providers/render-template-2024';
import universityDegreeCredentialTemplate2024 from '../../fixtures/univerisity-degree-credential-template-2024.json';

describe('RenderTemplate2024', () => {
let renderer: RenderTemplate2024;
Expand Down Expand Up @@ -293,4 +294,57 @@ describe('RenderTemplate2024', () => {
});
expect(renderedContent).toEqual({"renderedTemplate": "<p>John Doe</p>"});
});

it('should return error if the digestMultibase is provided but there is no context', async () => {
const document = universityDegreeCredentialTemplate2024;
const data = {
'https://w3id.org/security#digestMultibase': [
{
'@type': 'https://w3id.org/security#multibase',
'@value': 'abc123', // Replace with the actual hashed template value
},
],
'https://www.w3.org/2018/credentials#renderMethod#mediaQuery': [
{
'@value':
'@media (min-width: 1024px) {\n .title {\n font-weight: bold;\n color: #223675;\n }\n}',
},
],
'https://schema.org/encodingFormat': [
{
'@value': 'text/html',
},
],
'https://www.w3.org/2018/credentials#renderMethod#template': [
{
'@value':
'<p>{{name}}</p>',
},
],
'https://www.w3.org/2018/credentials#renderMethod#url': [
{
'@value': '',
},
],
};
const result = await renderer.renderCredential({
data,
document,
});
expect(result).toEqual({"renderedTemplate": 'Error: No hash function provided to verify the template'});
});

it('should return error for unsupported media type', async () => {
ducpm511 marked this conversation as resolved.
Show resolved Hide resolved
const data = {
'https://schema.org/encodingFormat': [{ '@value': 'unsupported/type' }],
};
const result = await renderer.renderCredential({
data,
context: undefined,
document: {},
});
expect(result.renderedTemplate).toBe('Error: Unsupported media type');
});


});
110 changes: 108 additions & 2 deletions packages/renderer/__tests__/renderer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import {
} from '@vckit/core-types';
import universityDegreeCredential from '../fixtures/university-degree-credential.json';
import universityDegreeCredentialTemplate2024 from '../fixtures/univerisity-degree-credential-template-2024.json';
import { RenderTemplate2024 } from '../src/providers/render-template-2024';
// import { extractRenderMethods } from '../src/renderer';

describe('Renderer', () => {
// Mock renderer provider
Expand Down Expand Up @@ -196,6 +194,114 @@ describe('Renderer', () => {
]);
});

it('should render a verifiable credential with multiple render methods', async () => {
// Mock data
const args: IRenderCredentialArgs = {
credential: {
...universityDegreeCredential,
render: [
{
template: 'template1',
'@type': 'WebRenderingTemplate2022',
},
{
template: 'template2',
'@type': 'WebRenderingTemplate2022',
},
],
},
};
const context = {};
// Call the renderCredential method
const result: IRenderResult = await renderer.renderCredential(
args,
context as IRendererContext
);
// Verify the result
expect(result.documents).toEqual([
{
renderedTemplate: 'RXJyb3I6IGludmFsaWQgdGVtcGxhdGUgcHJvdmlkZWQ=',
type: 'WebRenderingTemplate2022',
},
{
renderedTemplate: 'RXJyb3I6IGludmFsaWQgdGVtcGxhdGUgcHJvdmlkZWQ=',
type: 'WebRenderingTemplate2022',
},
]);
});

// it('should render a verifiable credential with no render methods', async () => {
// // Mock data
// const args: IRenderCredentialArgs = {
// credential: universityDegreeCredential,
// };
// const context = {};
// // Call the renderCredential method
// const result: IRenderResult = await renderer.renderCredential(
// args,
// context as IRendererContext
// );
// // Verify the result
// expect(result.documents).toEqual([]);
// });

// it('should render a verifiable credential with an empty credential object', async () => {
// // Mock data
// const args: IRenderCredentialArgs = {
// credential: {},
// };
// const context = {};
// // Call the renderCredential method
// const result: IRenderResult = await renderer.renderCredential(
// args,
// context as IRendererContext
// );
// // Verify the result
// expect(result.documents).toEqual([]);
// });

// it('should render a verifiable credential with an empty context object', async () => {
// // Mock data
// const args: IRenderCredentialArgs = {
// credential: universityDegreeCredential,
// };
// const context = {};
// // Call the renderCredential method
// const result: IRenderResult = await renderer.renderCredential(
// args,
// context as IRendererContext
// );
// // Verify the result
// expect(result.documents).toEqual([
// {
// renderedTemplate: 'RXJyb3I6IGludmFsaWQgdGVtcGxhdGUgcHJvdmlkZWQ=',
// type: 'WebRenderingTemplate2022',
// },
// ]);
// });

it('should throw an error if there is no context file for renderer', async () => {
// Mock data
const args: IRenderCredentialArgs = {
credential: {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://www.w3.org/2018/credentials/examples/v1',
],
id: 'http://example.edu/credentials/3732',
type: ['VerifiableCredential', 'UniversityDegreeCredential'],
issuer: 'https://example.edu/issuers/565049',
issuanceDate: '2010-01-01T00:00:00Z',
credentialSubject: {
id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
},
},
};
const context = {};
// Call the renderCredential method
await expect(
renderer.renderCredential(args, context as IRendererContext)
).rejects.toThrow();
});

});
Loading