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

Add unit tests for utils #537

Merged
merged 14 commits into from
Mar 15, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
test(util): implement units plugin storage
  • Loading branch information
narekhovhannisyan committed Mar 14, 2024
commit f9d68928e6adbc499397d58d4952d51ebe644870
67 changes: 67 additions & 0 deletions src/__tests__/unit/util/plugin-storage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import {pluginStorage} from '../../../util/plugin-storage';
import {ERRORS} from '../../../util/errors';

const {PluginInitalizationError} = ERRORS;

describe('util/pluginStorage: ', () => {
describe('pluginStorage(): ', () => {
describe('init(): ', () => {
it('should have get and set properties after initalization.', () => {
const storage = pluginStorage();

expect(storage).toHaveProperty('get');
expect(storage).toHaveProperty('set');
expect(typeof storage.get).toEqual('function');
expect(typeof storage.set).toEqual('function');
});
});

const pluginName = 'mock-plugin';
const pluginBody = {
execute: () => [{}],
metadata: {kind: 'mock-kind'},
};

describe('get(): ', () => {
it('throws error if record is not found.', () => {
const storage = pluginStorage();
const pluginName = 'mock-plugin';

try {
storage.get(pluginName);
} catch (error) {
expect(error).toBeInstanceOf(PluginInitalizationError);

if (error instanceof PluginInitalizationError) {
expect(error.message).toEqual;
}
}
});

it('gets data if there is stored one.', () => {
const storage = pluginStorage();
storage.set(pluginName, pluginBody);

const plugin = storage.get(pluginName);

expect(plugin).toEqual(pluginBody);
});
});

describe('set(): ', () => {
it('returns storage instance.', () => {
const storage = pluginStorage();
const instance = storage.set(pluginName, pluginBody);

expect(instance).toEqual(storage);
});

it('stores given data.', () => {
const storage = pluginStorage();
const instance = storage.set(pluginName, pluginBody);

expect(instance.get(pluginName)).toEqual(pluginBody);
});
});
});
});
Loading