Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions src/Functions/Common/Get/Get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* @module Intacct/SDK/Functions/Common/Get
*/

/**
* Copyright 2021 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import IaXmlWriter from "../../../Xml/IaXmlWriter";
import AbstractFunction from "../../AbstractFunction";

export default class Get extends AbstractFunction {
public object: string;
public key: string;
public fields: string[];

public writeXml(xml: IaXmlWriter): void {
if (this.object === undefined) {
throw new Error("required parameter 'object' undefined");
}
if (this.key === undefined) {
throw new Error("required parameter 'key' undefined");
}

xml.writeStartElement("function");
xml.writeAttribute("controlid", this.controlId, true);

xml.writeStartElement("get");
xml.writeAttribute("object", this.object);
xml.writeAttribute("key", this.key);

// optionally add fields to include in list
if (this.fields !== undefined) {
xml.writeStartElement("fields");
this.fields.forEach((field) => {
xml.writeElement("field", field);
});
xml.writeEndElement(); // fields
}

xml.writeEndElement(); // get_list

xml.writeEndElement(); // function
}
}
1 change: 1 addition & 0 deletions src/Functions/Common/Get/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Get } from "./Get";
11 changes: 11 additions & 0 deletions src/Functions/Common/GetList/GetList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,24 @@ import AbstractFunction from "../../AbstractFunction";
export default class GetList extends AbstractFunction {
public object: string;

public fields: string[];

public writeXml(xml: IaXmlWriter): void {
xml.writeStartElement("function");
xml.writeAttribute("controlid", this.controlId, true);

xml.writeStartElement("get_list");
xml.writeAttribute("object", this.object);

// optionally add fields to include in list
if (this.fields !== undefined) {
xml.writeStartElement("fields");
this.fields.forEach((field) => {
xml.writeElement("field", field);
});
xml.writeEndElement(); // fields
}

xml.writeEndElement(); // get_list

xml.writeEndElement(); // function
Expand Down
7 changes: 2 additions & 5 deletions src/Functions/Common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ export { default as ReadMore } from "./ReadMore";
export { default as Inspect } from "../Common/Inspect";
export { default as Lookup } from "../Common/Lookup";

import * as Get from "./Get/index";
import * as GetList from "./GetList/index";
import * as Query from "./Query/index";
import * as NewQuery from "./NewQuery/index";
export {
GetList,
Query,
NewQuery,
};
export { Get, GetList, Query, NewQuery };
70 changes: 70 additions & 0 deletions test/Functions/Common/Get/GetTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* Copyright 2020 Sage Intacct, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
* use this file except in compliance with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "LICENSE" file accompanying this file. This file is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

import * as chai from "chai";
import Get from "../../../../src/Functions/Common/Get/Get";
import XmlObjectTestHelper from "../../../Xml/XmlObjectTestHelper";

describe("Get", () => {
before((done) => {
return done();
});
beforeEach((done) => {
return done();
});
afterEach((done) => {
return done();
});
after((done) => {
return done();
});

it("should get supdoc (attachment)", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
<function controlid="unittest">
<get object="supdoc" key="A1234" />
</function>
</test>`;

const record = new Get("unittest");
record.object = "supdoc";
record.key = "A1234";

XmlObjectTestHelper.CompareXml(expected, record);
});

it("should get supdoc (attachment) fields", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
<function controlid="unittest">
<get object="supdoc" key="A1234">
<fields>
<field>supdocid</field>
<field>description</field>
<field>folder</field>
</fields>
</get>
</function>
</test>`;

const record = new Get("unittest");
record.object = "supdoc";
record.key = "A1234";
record.fields = ["supdocid", "description", "folder"];

XmlObjectTestHelper.CompareXml(expected, record);
});
});
22 changes: 22 additions & 0 deletions test/Functions/Common/GetList/GetListTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe("GetList", () => {
after((done) => {
return done();
});

it("should get company info", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
Expand All @@ -43,4 +44,25 @@ describe("GetList", () => {

XmlObjectTestHelper.CompareXml(expected, record);
});

it("should get company info fields", () => {
const expected = `<?xml version="1.0" encoding="utf-8" ?>
<test>
<function controlid="unittest">
<get_list object="supdoc">
<fields>
<field>supdocname</field>
<field>description</field>
<field>folder</field>
</fields>
</get_list>
</function>
</test>`;

const record = new GetList("unittest");
record.object = "supdoc";
record.fields = ["supdocname", "description", "folder"];

XmlObjectTestHelper.CompareXml(expected, record);
});
});