mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-01 13:47:27 +02:00
Add initial test
This commit is contained in:
parent
c3f1454df7
commit
fb9ff7b210
@ -21,17 +21,18 @@ const COLUMNS = [
|
||||
];
|
||||
const TABLE = 'client_instances';
|
||||
|
||||
const mapRow = (row) => ({
|
||||
const mapRow = (row): IClientInstance => ({
|
||||
appName: row.app_name,
|
||||
instanceId: row.instance_id,
|
||||
sdkVersion: row.sdk_version,
|
||||
sdkType: row.sdk_type, // should we add this?
|
||||
clientIp: row.client_ip,
|
||||
lastSeen: row.last_seen,
|
||||
createdAt: row.created_at,
|
||||
environment: row.environment,
|
||||
});
|
||||
|
||||
const mapToDb = (client) => ({
|
||||
const mapToDb = (client: INewClientInstance) => ({
|
||||
app_name: client.appName,
|
||||
instance_id: client.instanceId,
|
||||
sdk_version: client.sdkVersion || '',
|
||||
|
@ -11,6 +11,7 @@ export interface INewClientInstance {
|
||||
clientIp?: string;
|
||||
lastSeen?: Date;
|
||||
environment?: string;
|
||||
sdkType?: 'backend' | 'frontend' | null;
|
||||
}
|
||||
export interface IClientInstanceStore
|
||||
extends Store<
|
||||
|
60
src/test/e2e/stores/client-instance-store.e2e.test.ts
Normal file
60
src/test/e2e/stores/client-instance-store.e2e.test.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import faker from 'faker';
|
||||
import dbInit, { type ITestDb } from '../helpers/database-init.js';
|
||||
import getLogger from '../../fixtures/no-logger.js';
|
||||
import type {
|
||||
IClientInstanceStore,
|
||||
IUnleashStores,
|
||||
} from '../../../lib/types/index.js';
|
||||
import type { INewClientInstance } from '../../../lib/types/stores/client-instance-store.js';
|
||||
|
||||
let db: ITestDb;
|
||||
let stores: IUnleashStores;
|
||||
let clientInstanceStore: IClientInstanceStore;
|
||||
|
||||
beforeAll(async () => {
|
||||
db = await dbInit('client_application_store_e2e_serial', getLogger);
|
||||
stores = db.stores;
|
||||
clientInstanceStore = stores.clientInstanceStore;
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await db.destroy();
|
||||
});
|
||||
|
||||
test('Upserting an application keeps values not provided intact', async () => {
|
||||
const clientInstance: INewClientInstance = {
|
||||
appName: faker.internet.domainName(),
|
||||
instanceId: faker.datatype.uuid(),
|
||||
environment: 'development',
|
||||
sdkVersion: 'unleash-client-node:6.6.0',
|
||||
sdkType: 'backend',
|
||||
};
|
||||
await clientInstanceStore.insert(clientInstance);
|
||||
|
||||
const initial = await clientInstanceStore.get(clientInstance);
|
||||
|
||||
expect(initial).toMatchObject(clientInstance);
|
||||
|
||||
const update: INewClientInstance = {
|
||||
appName: clientInstance.appName,
|
||||
instanceId: clientInstance.instanceId,
|
||||
environment: clientInstance.environment,
|
||||
clientIp: '::2',
|
||||
};
|
||||
|
||||
await clientInstanceStore.insert(update);
|
||||
|
||||
const updated = await clientInstanceStore.get(clientInstance);
|
||||
|
||||
const expectedAfterUpdate = {
|
||||
clientIp: '::2',
|
||||
sdkVersion: 'unleash-client-node:6.6.0',
|
||||
sdkType: 'backend',
|
||||
};
|
||||
expect(updated).toMatchObject(expectedAfterUpdate);
|
||||
|
||||
await clientInstanceStore.bulkUpsert([clientInstance]);
|
||||
const doubleUpdated = await clientInstanceStore.get(clientInstance);
|
||||
|
||||
expect(doubleUpdated).toMatchObject(expectedAfterUpdate);
|
||||
});
|
Loading…
Reference in New Issue
Block a user