Skip to content

Commit

Permalink
🧪
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanc1 committed Oct 8, 2024
1 parent a20a631 commit 1eed8da
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dev": "npm run copy:version && npm run link && esbuild src/cli/index.ts --bundle --outfile=dist/zenodo.cjs --platform=node --external:fsevents --watch",
"test": "npm run copy:version && vitest run",
"test:watch": "npm run copy:version && vitest watch",
"lint": "eslint \"src/**/*.ts*\" -c ./.eslintrc.cjs",
"lint": "eslint \"src/**/!(*.spec).ts\" -c ./.eslintrc.cjs",
"lint:format": "prettier --check \"src/**/*.{ts,tsx,md}\"",
"build:esm": "tsc --project ./tsconfig.json --outDir dist",
"build:cli": "esbuild src/cli/index.ts --bundle --outfile=dist/zenodo.cjs --platform=node --external:fsevents",
Expand Down
56 changes: 56 additions & 0 deletions src/zenodoClient.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { Mock } from 'vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import type { DepositionMetadata } from './index.js';
import { AccessRight, UploadType, ZenodoClient } from './index.js';
import axios from 'axios';

// Mock axios module
vi.mock('axios');

describe('ZenodoClient Tests', () => {
let zenodoClient: ZenodoClient;
const ACCESS_TOKEN = 'fake_access_token';

beforeEach(() => {
// Mock axiosInstance.post to return the mock response
(axios.create as Mock).mockReturnValue({});
// Instantiate the ZenodoClient with the fake access token
zenodoClient = new ZenodoClient(ACCESS_TOKEN, true); // Use sandbox environment for testing
});

it('should instantiate ZenodoClient correctly', () => {
expect(zenodoClient).toBeInstanceOf(ZenodoClient);
});

it('should create a deposition', async () => {
// Mock response data
const mockDepositionResponse = {
data: {
id: 123456,
metadata: {
title: 'Test Deposition',
},
links: {
bucket: 'https://sandbox.zenodo.org/api/files/fake-bucket-id',
},
},
};

(zenodoClient as any).axiosInstance = {
post: vi.fn().mockResolvedValue(mockDepositionResponse),
};

const metadata: DepositionMetadata = {
upload_type: UploadType.presentation,
publication_date: '2023-10-10',
title: 'Test Presentation',
creators: [{ name: 'Doe, John' }],
description: 'A test deposition.',
access_right: AccessRight.open,
};

const deposition = await zenodoClient.createDeposition(metadata);

expect(deposition).toEqual(mockDepositionResponse.data);
});
});

0 comments on commit 1eed8da

Please sign in to comment.