How to use the @cumulus/common/test-utils.randomString function in @cumulus/common

To help you get started, we’ve selected a few @cumulus/common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nasa / cumulus / example / spec / parallel / kinesisTests / KinesisTestTriggerSpec.js View on Github external
beforeAll(async () => {
      const badRecord = { ...record };
      const badRecordIdentifier = randomString();
      badRecord.identifier = badRecordIdentifier;
      // Need to delete a property that will cause TranslateMessage to fail,
      // but not CnmResponseFail so that a failure message is still written
      // to the response stream
      delete badRecord.product.name;

      await tryCatchExit(cleanUp, async () => {
        console.log(`Dropping bad record onto ${streamName}, recordIdentifier: ${badRecordIdentifier}.`);
        await putRecordOnStream(streamName, badRecord);

        console.log('Waiting for step function to start...');
        failingWorkflowExecution = await waitForTestSf(badRecordIdentifier, testWorkflow, maxWaitForSFExistSecs, 'CNMToCMA');

        console.log(`Waiting for completed execution of ${failingWorkflowExecution.executionArn}.`);
        executionStatus = await waitForCompletedExecution(failingWorkflowExecution.executionArn, maxWaitForExecutionSecs);
      });
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeExecutionFactoryV2(params = {}) {
  const execution = {
    arn: randomString(),
    duration: 180.5,
    name: randomString(),
    execution: randomString(),
    parentArn: randomString(),
    error: { test: 'error' },
    status: 'completed',
    createdAt: Date.now() - 180.5 * 1000,
    updatedAt: Date.now(),
    timestamp: Date.now(),
    type: 'fakeWorkflow',
    originalPayload: { testInput: 'originalPayloadValue' },
    finalPayload: { testOutput: 'finalPayloadValue' },
    tasks: {}
  };

  return { ...execution, ...params };
}
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeExecutionFactoryV2(params = {}) {
  const execution = {
    arn: randomString(),
    duration: 180.5,
    name: randomString(),
    execution: randomString(),
    parentArn: randomString(),
    error: { test: 'error' },
    status: 'completed',
    createdAt: Date.now() - 180.5 * 1000,
    updatedAt: Date.now(),
    timestamp: Date.now(),
    type: 'fakeWorkflow',
    originalPayload: { testInput: 'originalPayloadValue' },
    finalPayload: { testOutput: 'finalPayloadValue' },
    tasks: {}
  };

  return { ...execution, ...params };
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeRuleFactoryV2(params = {}) {
  const rule = {
    name: randomString(),
    workflow: randomString(),
    provider: randomString(),
    collection: {
      name: randomString(),
      version: '0.0.0'
    },
    rule: {
      type: 'onetime'
    },
    state: 'DISABLED'
  };

  return { ...rule, ...params };
}
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeRuleFactoryV2(params = {}) {
  const rule = {
    name: randomString(),
    workflow: randomString(),
    provider: randomString(),
    collection: {
      name: randomString(),
      version: '0.0.0'
    },
    rule: {
      type: 'onetime'
    },
    state: 'DISABLED'
  };

  return { ...rule, ...params };
}
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeRuleFactoryV2(params = {}) {
  const rule = {
    name: randomString(),
    workflow: randomString(),
    provider: randomString(),
    collection: {
      name: randomString(),
      version: '0.0.0'
    },
    rule: {
      type: 'onetime'
    },
    state: 'DISABLED'
  };

  return { ...rule, ...params };
}
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeFileFactory(params = {}) {
  const fileName = randomId('name');

  return {
    bucket: randomString(),
    fileName,
    key: fileName,
    ...params
  };
}
github nasa / cumulus / packages / api / app / testAuth.js View on Github external
'use strict';

const { randomString } = require('@cumulus/common/test-utils');
const get = require('lodash.get');

let token = randomString();

/**
 * performs OAuth against an OAuth provider
 *
 * @param {Object} req - express request object
 * @param {Object} res - express response object
 * @returns {Promise} the promise of express response object
 */
async function tokenEndpoint(req, res) {
  const code = get(req, 'query.code');
  const state = get(req, 'query.state');
  if (token === '') token = randomString();

  if (code) {
    if (state) {
      return res
github nasa / cumulus / packages / api / lib / testUtils.js View on Github external
function fakeCollectionFactory(options = {}) {
  return Object.assign(
    {
      name: randomString(),
      dataType: randomString(),
      version: '0.0.0',
      provider_path: '',
      duplicateHandling: 'replace',
      granuleId: '^MOD09GQ\\.A[\\d]{7}\\.[\\S]{6}\\.006\\.[\\d]{13}$',
      granuleIdExtraction: '(MOD09GQ\\.(.*))\\.hdf',
      sampleFileName: 'MOD09GQ.A2017025.h21v00.006.2017034065104.hdf',
      files: []
    },
    options
  );
}
github nasa / cumulus / example / spec / parallel / kinesisTests / KinesisTestTriggerSpec.js View on Github external
beforeAll(async () => {
    testConfig = await loadConfig();
    const testId = createTimestampedTestId(testConfig.stackName, 'KinesisTestTrigger');
    testSuffix = createTestSuffix(testId);
    testDataFolder = createTestDataPath(testId);
    ruleSuffix = globalReplace(testSuffix, '-', '_');

    record = JSON.parse(fs.readFileSync(`${__dirname}/data/records/L2_HR_PIXC_product_0001-of-4154.json`));

    record.product.files[0].uri = globalReplace(record.product.files[0].uri, 'cumulus-test-data/pdrs', testDataFolder);
    record.provider += testSuffix;
    record.collection += testSuffix;

    granuleId = record.product.name;
    recordIdentifier = randomString();
    record.identifier = recordIdentifier;

    lambdaStep = new LambdaStep();

    recordFile = record.product.files[0];
    expectedTranslatePayload = {
      granules: [
        {
          granuleId: record.product.name,
          files: [
            {
              name: recordFile.name,
              type: recordFile.type,
              bucket: record.bucket,
              path: testDataFolder,
              url_path: recordFile.uri,