Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

Basic flow

  1. Prepare the necessary data and authorize the session | https://soldevelo.atlassian.net/wiki/spaces/QS/pages/4070899730/Rest+API#General-information

  2. Make a request:

    Status
    colourPurple
    titlePOST
    /import-test-cases?jwt=<YOUR_JWT>

    • Request body data model:

    Code Block
    type ImportData = {
      projectId: number | string;
      testCases: Array<TestCase>;
    };
    
    type TestCase = {
      name: string;
      testSteps: Array<TestStep>;
      [additionalField: string]?: {}; // eg. description, priority
    };
    
    type TestStep = {
      step: string;
      data: string;
      result: string;
    };

    • Request response data model:

    Code Block
    type ImportResult = {
      success: Array<{
        testCaseKey: string;
        name: string;
      }>;
      errors: Array<{
        name: string;
        details: {
          errorMessages: Array<string>;
          errors: Record<FieldName, string>;
        };
      }>;
    };

Script

Info

Example script is written in Deno.

.env

Take a look at https://soldevelo.atlassian.net/wiki/spaces/QS/pages/4070899730/Rest+API#General-information to find out how to get the required data.

Code Block
username=<your email>
password=<your Jira token>
jira_instance_name=<your Jira instance name>
project_id=<your project id>

index.ts

Code Block
languagetypescript
/**
 * Run command:
 * $ deno run --allow-read --allow-net index.ts
 */

import { load } from "https://deno.land/std@0.204.0/dotenv/mod.ts";

/**
 * MODELS
 */

type ImportData = {
  projectId: number | string;
  testCases: Array<TestCase>;
};

type TestCase = {
  name: string;
  testSteps: Array<TestStep>;
  [additionalField: string]?: {}; // eg. description, priority
};

type TestStep = {
  step: string;
  data: string;
  result: string;
};

type ImportResult = {
  success: Array<{
    testCaseKey: string;
    name: string;
  }>;
  errors: Array<{
    name: string;
    details: {
      errorMessages: Array<string>;
      errors: Record<FieldName, string>;
    };
  }>;
};

type FieldName = string;

/**
 * SETUP
 */

const env = await load();

const USERNAME = env["username"];
const PASSWORD = env["password"];
const JIRA_INSTANCE_NAME = env["jira_instance_name"];
const PROJECT_ID = env["project_id"];

const AUTH_URL = `https://${JIRA_INSTANCE_NAME}.atlassian.net/plugins/servlet/ac/com.soldevelo.apps.test_management_premium/test-cycles?classifier=json`;
const IMPORT_URL = `https://apps-qalityplus.soldevelo.com/import-test-cases`;

const MockTestCases: ImportData = {
  projectId: PROJECT_ID,
  testCases: [
    {
      testSteps: [
        {
          step: "Enter sample page",
          data: "www.example.com",
          result: "The sample page shows up",
        },
        {
          step: "Click on the “log-in” button",
          data: "",
          result: "The log-in form is shown",
        },
        {
          step: "Enter username and password",
          data: "user: admin, password: password",
          result: "The username is visible and the password is masked",
        },
        {
          step: "Click enter",
          data: "",
          result: "The user is logged in and redirected to the home page",
        },
      ],
      name: "Test Case import demo 123",
    },
    {
      testSteps: [
        {
          step: "Enter sample page",
          data: "www.example.com",
          result: "The sample page shows up",
        },
        {
          step: "Click on the “log-out” button",
          data: "",
          result: "The user is redirected to log-in page",
        },
      ],
      name: "Test Case import demo 1234",
    },
  ],
};

/**
 * FUNCTIONS
 */

const getJwt = async () => {
  const authResponse = await fetch(AUTH_URL, {
    headers: {
      Authorization: `Basic ${btoa(`${USERNAME}:${PASSWORD}`)}`,
    },
  });

  const json = await authResponse.json();
  return json["contextJwt"] as string;
};

const postTestCases = async (jwt: string) => {
  const importResponse = await fetch(`${IMPORT_URL}?jwt=${jwt}`, {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
    },
    body: JSON.stringify(MockTestCases),
  });

  console.log("Result ok?", importResponse.ok);
};

/**
 * MAIN
 */

const jwt = await getJwt();
await postTestCases(jwt);