All files / src/objects transaction.ts

89.04% Statements 65/73
78.78% Branches 26/33
75% Functions 6/8
89.04% Lines 65/73

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 66 67 68 69 70 71 72 73 741x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 75x 75x 1x 1x 15x 15x 15x 1x 1x           1x 1x       1x 1x 1x 1x 1x 1x 1x 7x 7x 7x 1x 1x 7x 7x 7x 1x 1x 29x 15x 15x 14x 14x 14x 14x 29x 29x 7x 7x 7x 29x 29x 29x 29x 29x 29x 4x 4x 7x 7x 7x 7x 1x  
import {AbstractObject} from "./_abstract_object";
import {xmlToArray} from "../xml_utils";
 
export class Transaction extends AbstractObject {
  private parsedXML: {
    description?: string,
    programName?: string,
    cinfo?: string,
    textsTranslations?: {language: string, description?: string}[],
  } | undefined;
 
  public getType(): string {
    return "TRAN";
  }
 
  public setDirty(): void {
    this.parsedXML = undefined;
    super.setDirty();
  }
 
  public getAllowedNaming() {
    return {
      maxLength: 20,
      allowNamespace: true,
    };
  }
 
  public getCInfo(): string | undefined {
    this.parse();
    return this.parsedXML?.cinfo;
  }
 
  public getProgramName(): string | undefined {
    this.parse();
    return this.parsedXML?.programName;
  }
 
  public getDescription(): string | undefined {
    this.parse();
    return this.parsedXML?.description;
  }
 
  public getTextsTranslations() {
    this.parse();
    return this.parsedXML?.textsTranslations;
  }
 
  public parse() {
    if (this.parsedXML) {
      return {updated: false, runtime: 0};
    }
 
    const start = Date.now();
    this.parsedXML = {};
    const parsed = super.parseRaw2();
    const values = parsed?.abapGit?.["asx:abap"]?.["asx:values"];
    if (values === undefined) {
      return {updated: false, runtime: 0};
    }
 
    this.parsedXML.description = values.TSTCT?.TTEXT;
    this.parsedXML.programName = values.TSTC?.PGMNA;
    this.parsedXML.cinfo = values.TSTC?.CINFO;
 
    this.parsedXML.textsTranslations = [];
    for (const item of xmlToArray(values.I18N_TPOOL?.TSTCT)) {
      this.parsedXML.textsTranslations.push({language: item.SPRSL, description: item.TTEXT});
    }
 
    const end = Date.now();
    return {updated: true, runtime: end - start};
  }
}