Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
zannis committed Dec 6, 2023
1 parent 747527c commit 036bb3c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 3 deletions.
49 changes: 49 additions & 0 deletions src/builders/__tests__/__snapshots__/open-action.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Given the "openAction" metadata builder when using it should return a valid OpenActionMetadata 1`] = `
{
"$schema": "https://json-schemas.lens.dev/open-actions/1.0.0.json",
"attributes": [
{
"key": "twitter",
"type": "String",
"value": "https://twitter.com/johndoe",
},
{
"key": "dob",
"type": "String",
"value": "1990-01-01T00:00:00Z",
},
],
"authors": [
"[email protected]",
],
"description": "
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris.
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Donec a diam lectus.
",
"initializeABI": [
{
"indexed": true,
"name": "address",
"type": "address",
},
{
"indexed": true,
"name": "price",
"type": "uint256",
},
],
"name": "Open Action Name",
"processABI": [
{
"indexed": true,
"name": "collector",
"type": "address",
},
],
"title": "Open Action Title",
}
`;
57 changes: 57 additions & 0 deletions src/builders/__tests__/open-action.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { describe, expect, it } from '@jest/globals';

import { MetadataAttributeType } from '../../MetadataAttribute.js';
import { openAction } from '../open-action';
import { faker } from '@faker-js/faker';
import { Markdown } from '../../primitives';

describe(`Given the "${openAction.name}" metadata builder`, () => {
describe(`when using it`, () => {
it('should return a valid OpenActionMetadata', () => {
const metadata = openAction({
name: 'Open Action Name',
title: 'Open Action Title',
authors: [faker.internet.email()],
attributes: [
{
key: 'twitter',
type: MetadataAttributeType.STRING,
value: 'https://twitter.com/johndoe',
},
{
key: 'dob',
type: MetadataAttributeType.STRING,
value: '1990-01-01T00:00:00Z',
},
],
description: `
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris.
- Lorem ipsum dolor sit amet, consectetur adipiscing elit.
- Donec a diam lectus.
` as Markdown,
initializeABI: [
{
type: 'address',
name: 'address',
indexed: true,
},
{
type: 'uint256',
name: 'price',
indexed: true,
},
],
processABI: [
{
type: 'address',
name: 'collector',
indexed: true,
},
],
});

expect(metadata).toMatchSnapshot();
});
});
});
8 changes: 5 additions & 3 deletions src/open-actions/OpenActionMetadataSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { StringAttributeSchema, StringAttribute } from '../MetadataAttribute';
export type OpenActionMetadata = {
name: string;
title: string;
content: Markdown;
description: Markdown;
authors: string[];
initializeABI: EventParameter[];
processABI: EventParameter[];
Expand All @@ -21,8 +21,10 @@ export type OpenActionMetadata = {
export const OpenActionMetadataSchema: z.ZodType<OpenActionMetadata, z.ZodTypeDef, object> =
z.object({
name: nonEmptyStringSchema('The name of the Open Action.').max(200),
title: nonEmptyStringSchema('The title, or short description, of the Open Action.'),
content: markdownSchema('Markdown formatted content'),
title: nonEmptyStringSchema(
'The title of the Open Action. Best to be in a human friendly format.',
),
description: markdownSchema('Markdown formatted description of the open action.'),
authors: z
.array(z.string().min(1).email('Authors list should only contain valid emails'))
.min(1, 'You must supply at least one author'),
Expand Down

0 comments on commit 036bb3c

Please sign in to comment.