Skip to content

Commit

Permalink
refactor: Make the drop IDs property optional when creating a Moment (#…
Browse files Browse the repository at this point in the history
…144)

To create a Moment without any drop links, it was mandatory to pass in
an empty array. This is not a requirement in the API, so this PR removes
the requirement from the SDK as well.
  • Loading branch information
reobin authored Nov 13, 2024
1 parent 455071c commit 2df3ee9
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 24 deletions.
6 changes: 3 additions & 3 deletions packages/drops/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/drops",
"version": "0.7.1",
"version": "0.7.2",
"description": "Drops module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down Expand Up @@ -29,7 +29,7 @@
"node": ">=18"
},
"dependencies": {
"@poap-xyz/providers": "0.7.1",
"@poap-xyz/utils": "0.7.1"
"@poap-xyz/providers": "0.7.2",
"@poap-xyz/utils": "0.7.2"
}
}
6 changes: 3 additions & 3 deletions packages/moments/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/moments",
"version": "0.7.1",
"version": "0.7.2",
"description": "Moments module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.7.1",
"@poap-xyz/utils": "0.7.1",
"@poap-xyz/providers": "0.7.2",
"@poap-xyz/utils": "0.7.2",
"uuid": "^9.0.0"
},
"engines": {
Expand Down
36 changes: 36 additions & 0 deletions packages/moments/src/client/MomentsClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,41 @@ describe('MomentsClient', () => {
expect(onStepUpdate).toHaveBeenCalledWith(CreateSteps.FINISHED);
expect(onStepUpdate).toHaveBeenCalledTimes(2);
});

it('should allow creation of a moment without any drops', async () => {
// GIVEN
const client = new MomentsClient(
poapMomentsAPIMocked,
compassProviderMocked,
);
const inputs: CreateMomentInput = {
mediaKeys: MEDIA_KEYS,
author: AUTHOR,
description: DESCRIPTION,
};
poapMomentsAPIMocked.createMoment.mockResolvedValue({
id: MOMENT_ID,
author: AUTHOR,
createdOn: new Date().toISOString(),
dropIds: [],
});

const EXPECTED_MOMENT_CREATE_INPUT = {
author: AUTHOR,
description: DESCRIPTION,
mediaKeys: MEDIA_KEYS,
};

// WHEN
const moment = await client.createMoment(inputs);

// THEN
expect(moment.id).toBe(MOMENT_ID);
expect(moment.author).toBe(AUTHOR);
expect(moment.dropIds).toEqual([]);
expect(poapMomentsAPIMocked.createMoment).toHaveBeenCalledWith(
EXPECTED_MOMENT_CREATE_INPUT,
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface CreateAndUploadMomentInput {
/** The description of the moment. */
description?: string;
/** The IDs of the drops to associate to the moment. */
dropIds: number[];
dropIds?: number[];
/** The amount of time to wait until media is processed. */
timeOut?: number;
/** Callback function to be called when the progress step changes. */
Expand Down
2 changes: 1 addition & 1 deletion packages/moments/src/client/dtos/create/CreateInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface CreateMomentInput {
/** The description of the moment. */
description?: string;
/** The IDs of the drops to associate to the moment. */
dropIds: number[];
dropIds?: number[];
/** The amount of time to wait until media is processed. */
timeOut?: number;
/** Callback function to be called when the step changes. */
Expand Down
6 changes: 3 additions & 3 deletions packages/poaps/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/poaps",
"version": "0.7.1",
"version": "0.7.2",
"description": "Poaps module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,8 +26,8 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/providers": "0.7.1",
"@poap-xyz/utils": "0.7.1"
"@poap-xyz/providers": "0.7.2",
"@poap-xyz/utils": "0.7.2"
},
"engines": {
"node": ">=18"
Expand Down
4 changes: 2 additions & 2 deletions packages/providers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/providers",
"version": "0.7.1",
"version": "0.7.2",
"description": "Providers module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand All @@ -26,7 +26,7 @@
"build": "rollup -c --bundleConfigAsCjs"
},
"dependencies": {
"@poap-xyz/utils": "0.7.1",
"@poap-xyz/utils": "0.7.2",
"axios": "^1.6.8",
"lodash.chunk": "^4.2.0"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/** Object describing the input required to create a Moment */
export interface CreateMomentInput {
/** The IDs of the Drops to associate with the Moment */
dropIds: number[];
dropIds?: number[];
/** The author of the Moment. An Ethereum address. */
author: string;
/** The media keys associated with the Moment */
Expand Down
18 changes: 18 additions & 0 deletions packages/providers/test/PoapMomentsApi.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,5 +132,23 @@ describe('PoapMomentsApi', () => {
api = new PoapMomentsApi({});
await expect(api.createMoment(createMomentInput)).rejects.toThrow();
});

it('should allow Moment creation without any drop', async () => {
const mockResponse: CreateMomentResponse = {
id: '1',
author: '0x1234',
createdOn: '2023-01-01T00:00:00.000Z',
dropIds: [],
description: 'This is a test description',
};

axiosMocked.onPost(`${BASE_URL}/moments`).reply(200, mockResponse);

const input = { ...createMomentInput };
delete input.dropIds;

const result = await api.createMoment(input);
expect(result).toEqual(mockResponse);
});
});
});
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@poap-xyz/utils",
"version": "0.7.1",
"version": "0.7.2",
"description": "Utils module for the poap.js library",
"main": "dist/cjs/index.cjs",
"module": "dist/esm/index.mjs",
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -884,8 +884,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/drops@workspace:packages/drops"
dependencies:
"@poap-xyz/providers": 0.7.1
"@poap-xyz/utils": 0.7.1
"@poap-xyz/providers": 0.7.2
"@poap-xyz/utils": 0.7.2
languageName: unknown
linkType: soft

Expand All @@ -901,8 +901,8 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/moments@workspace:packages/moments"
dependencies:
"@poap-xyz/providers": 0.7.1
"@poap-xyz/utils": 0.7.1
"@poap-xyz/providers": 0.7.2
"@poap-xyz/utils": 0.7.2
"@types/uuid": ^9.0.2
uuid: ^9.0.0
languageName: unknown
Expand All @@ -912,24 +912,24 @@ __metadata:
version: 0.0.0-use.local
resolution: "@poap-xyz/poaps@workspace:packages/poaps"
dependencies:
"@poap-xyz/providers": 0.7.1
"@poap-xyz/utils": 0.7.1
"@poap-xyz/providers": 0.7.2
"@poap-xyz/utils": 0.7.2
languageName: unknown
linkType: soft

"@poap-xyz/providers@0.7.1, @poap-xyz/providers@workspace:packages/providers":
"@poap-xyz/providers@0.7.2, @poap-xyz/providers@workspace:packages/providers":
version: 0.0.0-use.local
resolution: "@poap-xyz/providers@workspace:packages/providers"
dependencies:
"@poap-xyz/utils": 0.7.1
"@poap-xyz/utils": 0.7.2
axios: ^1.6.8
axios-mock-adapter: ^1.21.4
jest-fetch-mock: ^3.0.3
lodash.chunk: ^4.2.0
languageName: unknown
linkType: soft

"@poap-xyz/utils@0.7.1, @poap-xyz/utils@workspace:packages/utils":
"@poap-xyz/utils@0.7.2, @poap-xyz/utils@workspace:packages/utils":
version: 0.0.0-use.local
resolution: "@poap-xyz/utils@workspace:packages/utils"
languageName: unknown
Expand Down

0 comments on commit 2df3ee9

Please sign in to comment.