@pinecone-database/pinecone
Version:
This is the official Node.js SDK for [Pinecone](https://www.pinecone.io), written in TypeScript.
47 lines • 2.33 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const createIndexFromBackup_1 = require("../createIndexFromBackup");
const errors_1 = require("../../errors");
const setupCreateIndexFromBackupResponse = (createIndexFromBackupResponse = {}, isCreateIndexFromBackupSuccess = true) => {
const fakeCreateIndexFromBackup = jest
.fn()
.mockImplementation(() => isCreateIndexFromBackupSuccess
? Promise.resolve(createIndexFromBackupResponse)
: Promise.reject(createIndexFromBackupResponse));
const MIA = {
createIndexFromBackupOperation: fakeCreateIndexFromBackup,
};
return MIA;
};
describe('createIndexFromBackup', () => {
test('calls the openapi create indexn from backup endpoint, passing backupId, name, tags, and deletionProtection', async () => {
const MIA = setupCreateIndexFromBackupResponse();
const returned = await (0, createIndexFromBackup_1.createIndexFromBackup)(MIA)({
backupId: '12345-ajfielkas-123123',
name: 'my-restored-index',
tags: { test: 'test-tag' },
deletionProtection: 'enabled',
});
expect(returned).toEqual({});
expect(MIA.createIndexFromBackupOperation).toHaveBeenCalledWith({
backupId: '12345-ajfielkas-123123',
createIndexFromBackupRequest: {
name: 'my-restored-index',
tags: { test: 'test-tag' },
deletionProtection: 'enabled',
},
});
});
test('throws an error if backupId or name are not provided', async () => {
const MIA = setupCreateIndexFromBackupResponse();
await expect((0, createIndexFromBackup_1.createIndexFromBackup)(MIA)({
backupId: '',
name: 'my-restored-index',
})).rejects.toThrow(new errors_1.PineconeArgumentError('You must pass a non-empty string for `backupId` in order to create an index from backup'));
await expect((0, createIndexFromBackup_1.createIndexFromBackup)(MIA)({
backupId: '123-123-123-123',
name: '',
})).rejects.toThrow(new errors_1.PineconeArgumentError('You must pass a non-empty string for `name` in order to create an index from backup'));
});
});
//# sourceMappingURL=createIndexFromBackup.test.js.map
;