Add tests
This commit is contained in:
parent
cfe296bcc9
commit
42eefddd5c
|
@ -656,6 +656,122 @@ if (descriptions.length) {
|
||||||
{ id: expectValidId },
|
{ id: expectValidId },
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("can handle all bson field types", async () => {
|
||||||
|
collection = generator.guid()
|
||||||
|
await withCollection(async collection => {
|
||||||
|
await collection.insertOne({
|
||||||
|
_id: new BSON.ObjectId("65b0123456789abcdef01234"),
|
||||||
|
stringField: "This is a string",
|
||||||
|
numberField: 42,
|
||||||
|
doubleField: new BSON.Double(42.42),
|
||||||
|
integerField: new BSON.Int32(123),
|
||||||
|
longField: new BSON.Long("9223372036854775807"),
|
||||||
|
booleanField: true,
|
||||||
|
nullField: null,
|
||||||
|
arrayField: [1, 2, 3, "four", { nested: true }],
|
||||||
|
objectField: {
|
||||||
|
nestedString: "nested",
|
||||||
|
nestedNumber: 99,
|
||||||
|
},
|
||||||
|
dateField: { $date: "2025-01-30T12:00:00Z" },
|
||||||
|
// timestampField: new BSON.Timestamp({ t: 1706616000, i: 1 }),
|
||||||
|
binaryField: new BSON.Binary(
|
||||||
|
new TextEncoder().encode("bufferValue")
|
||||||
|
),
|
||||||
|
objectIdField: new BSON.ObjectId("65b0123456789abcdef01235"),
|
||||||
|
regexField: new BSON.BSONRegExp("^Hello.*", "i"),
|
||||||
|
minKeyField: new BSON.MinKey(),
|
||||||
|
maxKeyField: new BSON.MaxKey(),
|
||||||
|
decimalField: new BSON.Decimal128("12345.6789"),
|
||||||
|
codeField: new BSON.Code(
|
||||||
|
"function() { return 'Hello, World!'; }"
|
||||||
|
),
|
||||||
|
codeWithScopeField: new BSON.Code(
|
||||||
|
"function(x) { return x * 2; }",
|
||||||
|
{ x: 10 }
|
||||||
|
),
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
const query = await createQuery({
|
||||||
|
fields: {
|
||||||
|
json: {},
|
||||||
|
extra: {
|
||||||
|
actionType: "find",
|
||||||
|
collection,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
transformer: "return data.map(x => ({ ...x }))",
|
||||||
|
})
|
||||||
|
|
||||||
|
const result = await config.api.query.execute(query._id!)
|
||||||
|
|
||||||
|
expect(result.data).toEqual([
|
||||||
|
{
|
||||||
|
_id: "65b0123456789abcdef01234",
|
||||||
|
arrayField: [
|
||||||
|
1,
|
||||||
|
2,
|
||||||
|
3,
|
||||||
|
"four",
|
||||||
|
{
|
||||||
|
nested: true,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
binaryField: "YnVmZmVyVmFsdWU=",
|
||||||
|
booleanField: true,
|
||||||
|
codeField: {
|
||||||
|
code: "function() { return 'Hello, World!'; }",
|
||||||
|
},
|
||||||
|
codeWithScopeField: {
|
||||||
|
code: "function(x) { return x * 2; }",
|
||||||
|
scope: {
|
||||||
|
x: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dateField: "2025-01-30T12:00:00.000Z",
|
||||||
|
decimalField: {
|
||||||
|
bytes: {
|
||||||
|
"0": 21,
|
||||||
|
"1": 205,
|
||||||
|
"10": 0,
|
||||||
|
"11": 0,
|
||||||
|
"12": 0,
|
||||||
|
"13": 0,
|
||||||
|
"14": 56,
|
||||||
|
"15": 48,
|
||||||
|
"2": 91,
|
||||||
|
"3": 7,
|
||||||
|
"4": 0,
|
||||||
|
"5": 0,
|
||||||
|
"6": 0,
|
||||||
|
"7": 0,
|
||||||
|
"8": 0,
|
||||||
|
"9": 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
doubleField: 42.42,
|
||||||
|
integerField: 123,
|
||||||
|
longField: {
|
||||||
|
high: 2147483647,
|
||||||
|
low: -1,
|
||||||
|
unsigned: false,
|
||||||
|
},
|
||||||
|
maxKeyField: {},
|
||||||
|
minKeyField: {},
|
||||||
|
nullField: null,
|
||||||
|
numberField: 42,
|
||||||
|
objectField: {
|
||||||
|
nestedNumber: 99,
|
||||||
|
nestedString: "nested",
|
||||||
|
},
|
||||||
|
objectIdField: "65b0123456789abcdef01235",
|
||||||
|
regexField: {},
|
||||||
|
stringField: "This is a string",
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should throw an error if the incorrect actionType is specified", async () => {
|
it("should throw an error if the incorrect actionType is specified", async () => {
|
||||||
|
|
Loading…
Reference in New Issue