1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-23 20:07:40 +02:00
unleash.unleash/src/test/e2e/stores/user-feedback-store.e2e.test.ts
Christopher Kolstad f85f66d4f5
feat: add project and environment columns to events (#942)
* feat: add project and environment columns to events

* Added events for feature_strategy update

* fix duplicate test key for dbInit

* Fix argument list for toggleService calls in tests
2021-09-20 12:13:38 +02:00

89 lines
2.4 KiB
TypeScript

import { IUserFeedbackStore } from 'lib/types/stores/user-feedback-store';
import { IUserStore } from 'lib/types/stores/user-store';
import dbInit from '../helpers/database-init';
import getLogger from '../../fixtures/no-logger';
let stores;
let db;
let userFeedbackStore: IUserFeedbackStore;
let userStore: IUserStore;
let currentUser;
beforeAll(async () => {
db = await dbInit('user_feedback_store', getLogger);
stores = db.stores;
userFeedbackStore = stores.userFeedbackStore;
userStore = stores.userStore;
currentUser = await userStore.upsert({ email: 'me.feedback@mail.com' });
});
afterAll(async () => {
await db.destroy();
});
afterEach(async () => {
await userFeedbackStore.deleteAll();
});
test('should create userFeedback', async () => {
await userFeedbackStore.updateFeedback({
feedbackId: 'some-id',
userId: currentUser.id,
neverShow: false,
given: new Date(),
});
const userFeedbacks = await userFeedbackStore.getAllUserFeedback(
currentUser.id,
);
expect(userFeedbacks).toHaveLength(1);
expect(userFeedbacks[0].feedbackId).toBe('some-id');
});
test('should get userFeedback', async () => {
await userFeedbackStore.updateFeedback({
feedbackId: 'some-id',
userId: currentUser.id,
neverShow: false,
given: new Date(),
});
const userFeedback = await userFeedbackStore.getFeedback(
currentUser.id,
'some-id',
);
expect(userFeedback.feedbackId).toBe('some-id');
});
test('should exists', async () => {
await userFeedbackStore.updateFeedback({
feedbackId: 'some-id-3',
userId: currentUser.id,
neverShow: false,
given: new Date(),
});
const exists = await userFeedbackStore.exists({
userId: currentUser.id,
feedbackId: 'some-id-3',
});
expect(exists).toBe(true);
});
test('should not exists', async () => {
const exists = await userFeedbackStore.exists({
userId: currentUser.id,
feedbackId: 'some-id-not-here',
});
expect(exists).toBe(false);
});
test('should get all userFeedbacks', async () => {
await userFeedbackStore.updateFeedback({
feedbackId: 'some-id-2',
userId: currentUser.id,
neverShow: false,
given: new Date(),
});
const userFeedbacks = await userFeedbackStore.getAll();
expect(userFeedbacks).toHaveLength(1);
expect(userFeedbacks[0].feedbackId).toBe('some-id-2');
});