All files / test dataProvider.ts

93.1% Statements 27/29
50% Branches 2/4
100% Functions 1/1
93.1% Lines 27/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 663x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   3x 3x 3x 3x           3x     3x   3x     3x   3x 3x   3x           3x           3x             3x                    
import { appInstall, DEFAULT_ACCESS_TOKEN, DEFAULT_USER } from '@orchesty/nodejs-connectors/test/DataProvider';
import { container } from '@orchesty/nodejs-connectors/test/TestAbstract';
import CoreFormsEnum from '@orchesty/nodejs-sdk/dist/lib/Application/Base/CoreFormsEnum';
import { ACCESS_TOKEN } from '@orchesty/nodejs-sdk/dist/lib/Authorization/Provider/OAuth2/OAuth2Provider';
import CacheService from '@orchesty/nodejs-sdk/dist/lib/Cache/CacheService';
import { getEnv } from '@orchesty/nodejs-sdk/dist/lib/Config/Config';
import DatabaseClient from '@orchesty/nodejs-sdk/dist/lib/Storage/Database/Client';
import Redis from '@orchesty/nodejs-sdk/dist/lib/Storage/Redis/Redis';
import CurlSender from '@orchesty/nodejs-sdk/dist/lib/Transport/Curl/CurlSender';
import PinyaAbsencesBatch from '../src/Batch/PinyaAbsencesBatch';
import PinyaEmployeesBatch from '../src/Batch/PinyaEmployeesBatch';
import { PinyaJobTitlesConnector } from '../src/Connector/PinyaJobTitlesConnector';
import PinyaApplication, { PINYA_APPLICATION } from '../src/PinyaApplication';
 
export async function initPinyaIntegrationTest(): Promise<void> {
    const sender = container.get(CurlSender);
    const db = container.get(DatabaseClient);
    appInstall(PINYA_APPLICATION, DEFAULT_USER, {
        [CoreFormsEnum.AUTHORIZATION_FORM]: {
            [ACCESS_TOKEN]: DEFAULT_ACCESS_TOKEN,
        },
    });
 
    Iif (!container.has(Redis)) {
        container.set(new Redis(getEnv('REDIS_DSN')));
    }
    const redisService = container.get(Redis);
 
    Iif (!container.has(CacheService)) {
        container.set(new CacheService(redisService, sender));
    }
    const cacheService = container.get(CacheService);
 
    const app = new PinyaApplication(cacheService);
    container.setApplication(app);
 
    container.setNode(
        new PinyaEmployeesBatch()
            .setSender(sender)
            .setDb(db)
            .setApplication(app),
    );
    container.setNode(
        new PinyaAbsencesBatch()
            .setSender(sender)
            .setDb(db)
            .setApplication(app),
    );
    container.setNode(
        new PinyaJobTitlesConnector()
            .setSender(sender)
            .setDb(db)
            .setApplication(app),
    );
 
    await redisService.set(
        'pinya-accessKey',
        JSON.stringify({
            accessToken: 'accessToken',
            refreshToken: 'refreshToken',
            expiration: new Date().getTime() + 1_000,
        }),
        100,
    );
}