Skip to content

Commit 5a08750

Browse files
committed
테스트 보강
1 parent 0af979b commit 5a08750

6 files changed

Lines changed: 51 additions & 147 deletions

File tree

package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "xapi-js",
33
"private": true,
4-
"version": "1.0.0",
4+
"version": "1.1.0",
55
"description": "A TypeScript implementation of Tobesoft's X-API for communication with Nexacro Platform and XPlatform solutions.",
66
"repository": {
77
"type": "git",
@@ -25,10 +25,7 @@
2525
"devDependencies": {
2626
"@vitest/coverage-v8": "^3.2.4",
2727
"@vitest/ui": "^3.2.4",
28-
"mitata": "^1.0.34",
29-
"ts-node": "^10.9.2",
3028
"tsup": "^8.0.2",
31-
"txml": "^5.1.1",
3229
"typescript": "^5.0.0",
3330
"vitest": "^3.2.4"
3431
}

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
"@types/xml2js": "^0.4.14",
4444
"fast-xml-parser": "^5.2.5",
4545
"stax-xml": "^0.2.4",
46+
"txml": "^5.1.1",
4647
"xml2js": "^0.6.2"
4748
}
4849
}

packages/core/src/utils.ts

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,6 @@ import { ColumnType, ColumnTypeError, XapiValueType } from "./types";
22

33
// make ReadableStream to string
44
// can be async
5-
export function readStreamReadAll(stream: ReadableStream<Uint8Array>): Promise<string> {
6-
const reader = stream.getReader();
7-
const decoder = new TextDecoder();
8-
let result = '';
9-
10-
return new Promise((resolve, reject) => {
11-
function read() {
12-
reader.read().then(({ done, value }) => {
13-
if (done) {
14-
resolve(result);
15-
} else {
16-
result += decoder.decode(value, { stream: true });
17-
read();
18-
}
19-
}).catch(reject);
20-
}
21-
read();
22-
});
23-
}
24-
255
export function arrayBufferToString(buffer: ArrayBuffer): string {
266
const decoder = new TextDecoder();
277
return decoder.decode(buffer);

packages/core/test/handler.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ describe("Xapi Handler Tests", () => {
895895
</Rows>
896896
</Dataset>
897897
</Root>`;
898-
expect(() => parse(invalidXml)).toThrow("Unsupported column type: ERROR_TYPE");
898+
expect(() => parse(invalidXml)).toThrow("Column type for testCol not found in dataset invalid");
899899
});
900900

901901
});

packages/core/test/utils.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { describe, expect, it } from "vitest";
22
import { ColumnType, ColumnTypeError } from "../src";
33
import {
44
StringWritableStream,
5+
_unescapeXml,
6+
arrayBufferToString,
57
base64ToUint8Array,
68
convertToColumnType,
79
dateToString,
@@ -230,4 +232,47 @@ describe("Utils Tests", () => {
230232
expect(() => convertToColumnType("123", "UNKNOWN" as ColumnType)).toThrow(ColumnTypeError); // Unsupported
231233
})
232234
})
235+
236+
describe("arrayBufferToString", () => {
237+
it("should convert ArrayBuffer to string", () => {
238+
const encoder = new TextEncoder();
239+
const buffer = encoder.encode("Hello World").buffer;
240+
const result = arrayBufferToString(buffer);
241+
expect(result).toBe("Hello World");
242+
});
243+
244+
it("should handle empty ArrayBuffer", () => {
245+
const buffer = new ArrayBuffer(0);
246+
const result = arrayBufferToString(buffer);
247+
expect(result).toBe("");
248+
});
249+
})
250+
describe("_unescapeXml", () => {
251+
it("should unescape XML entities", () => {
252+
const input = `Test &#10;`;
253+
const expected = "Test \x0A";
254+
const result = _unescapeXml(input);
255+
expect(result).toBe(expected);
256+
});
257+
258+
it("should handle empty string", () => {
259+
const input = "";
260+
const expected = "";
261+
const result = _unescapeXml(input);
262+
expect(result).toBe(expected);
263+
});
264+
265+
it("should handle no entities", () => {
266+
const input = "Hello World";
267+
const expected = "Hello World";
268+
const result = _unescapeXml(input);
269+
expect(result).toBe(expected);
270+
});
271+
it("should handle undefined input", () => {
272+
const input = undefined;
273+
const expected = undefined;
274+
const result = _unescapeXml(input);
275+
expect(result).toBe(expected);
276+
});
277+
})
233278
});

0 commit comments

Comments
 (0)