mirror of
https://github.com/lowdefy/lowdefy.git
synced 2025-02-23 14:39:32 +08:00
Merge branch 'develop' into docs-display
This commit is contained in:
commit
ced932d4d9
@ -3,6 +3,9 @@ module.exports = {
|
||||
instance: {
|
||||
dbName: 'test',
|
||||
},
|
||||
binary: {
|
||||
version: '4.4.3',
|
||||
},
|
||||
autoStart: false,
|
||||
},
|
||||
};
|
||||
|
@ -19,9 +19,22 @@ import { serialize, deserialize } from '../serialize';
|
||||
|
||||
import schema from './MongoDBAggregationSchema.json';
|
||||
|
||||
function checkOutAndMerge({ pipeline, connection }) {
|
||||
if (connection.write !== true) {
|
||||
pipeline.forEach((stage) => {
|
||||
if (stage.$out != null || stage.$merge != null) {
|
||||
throw new Error(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
async function mongodbAggregation({ request, connection }) {
|
||||
const deserializedRequest = deserialize(request);
|
||||
const { pipeline, options } = deserializedRequest;
|
||||
checkOutAndMerge({ pipeline, connection });
|
||||
const { collection, client } = await getCollection({ connection });
|
||||
let res;
|
||||
try {
|
||||
|
@ -147,3 +147,77 @@ test('aggregation options not an object', async () => {
|
||||
'MongoDBAggregation request property "options" should be an object.'
|
||||
);
|
||||
});
|
||||
|
||||
test('$out is not allowed with write undefined', async () => {
|
||||
const request = { pipeline: [{ $out: 'outCollection' }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
};
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
|
||||
test('$out is not allowed with write false', async () => {
|
||||
const request = { pipeline: [{ $out: 'outCollection' }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
write: false,
|
||||
};
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
|
||||
test('$out is allowed with write true', async () => {
|
||||
const request = { pipeline: [{ $out: 'outCollection' }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await resolver({ request, connection });
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
|
||||
test('$merge is not allowed with write undefined', async () => {
|
||||
const request = { pipeline: [{ $merge: { into: 'mergeCollection' } }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
};
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
|
||||
test('$merge is not allowed with write false', async () => {
|
||||
const request = { pipeline: [{ $merge: { into: 'mergeCollection' } }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
write: false,
|
||||
};
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'Connection does not allow writes and aggregation pipeline contains a "$merge" or "$out" stage.'
|
||||
);
|
||||
});
|
||||
|
||||
test('$merge is allowed with write true', async () => {
|
||||
const request = { pipeline: [{ $merge: { into: 'mergeCollection' } }] };
|
||||
const connection = {
|
||||
databaseUri,
|
||||
databaseName,
|
||||
collection,
|
||||
write: true,
|
||||
};
|
||||
const res = await resolver({ request, connection });
|
||||
expect(res).toEqual([]);
|
||||
});
|
||||
|
@ -101,7 +101,7 @@ test('insertMany mongodb error', async () => {
|
||||
};
|
||||
await resolver({ request, connection });
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'E11000 duplicate key error dup key: { : "insertMany9-1" }'
|
||||
'E11000 duplicate key error collection: test.insertMany index: _id_ dup key: { _id: "insertMany9-1" }'
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -93,7 +93,7 @@ test('insertOne mongodb error', async () => {
|
||||
};
|
||||
await resolver({ request, connection });
|
||||
await expect(resolver({ request, connection })).rejects.toThrow(
|
||||
'E11000 duplicate key error dup key'
|
||||
'E11000 duplicate key error collection: test.insertOne index: _id_ dup key: { _id: "insertOne_mongodb_error" }'
|
||||
);
|
||||
});
|
||||
|
||||
|
@ -57,13 +57,13 @@ class RequestController {
|
||||
});
|
||||
|
||||
this.checkConnectionRead({
|
||||
connectionId: request.connectionId,
|
||||
connectionProperties,
|
||||
connection,
|
||||
checkRead: requestDefinition.checkRead,
|
||||
});
|
||||
this.checkConnectionWrite({
|
||||
connectionId: request.connectionId,
|
||||
connectionProperties,
|
||||
connection,
|
||||
checkWrite: requestDefinition.checkWrite,
|
||||
});
|
||||
|
||||
@ -176,15 +176,15 @@ class RequestController {
|
||||
};
|
||||
}
|
||||
|
||||
checkConnectionRead({ connectionProperties, connection, checkRead }) {
|
||||
checkConnectionRead({ connectionId, connectionProperties, checkRead }) {
|
||||
if (checkRead && connectionProperties.read === false) {
|
||||
throw new ConfigurationError(`${connection.type} connection does not allow reads.`);
|
||||
throw new ConfigurationError(`Connection "${connectionId}" does not allow reads.`);
|
||||
}
|
||||
}
|
||||
|
||||
checkConnectionWrite({ connectionProperties, connection, checkWrite }) {
|
||||
checkConnectionWrite({ connectionId, connectionProperties, checkWrite }) {
|
||||
if (checkWrite && connectionProperties.write !== true) {
|
||||
throw new ConfigurationError(`${connection.type} connection does not allow writes.`);
|
||||
throw new ConfigurationError(`Connection "${connectionId}" does not allow writes.`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -741,7 +741,7 @@ test('checkRead, read explicitly false', async () => {
|
||||
const controller = createRequestController(context);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(ConfigurationError);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(
|
||||
'TestConnection connection does not allow reads.'
|
||||
'Connection "testConnection" does not allow reads.'
|
||||
);
|
||||
});
|
||||
|
||||
@ -855,7 +855,7 @@ test('checkWrite, write explicitly false', async () => {
|
||||
const controller = createRequestController(context);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(ConfigurationError);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(
|
||||
'TestConnection connection does not allow writes.'
|
||||
'Connection "testConnection" does not allow writes.'
|
||||
);
|
||||
});
|
||||
|
||||
@ -887,6 +887,6 @@ test('checkWrite, write not set', async () => {
|
||||
const controller = createRequestController(context);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(ConfigurationError);
|
||||
await expect(controller.callRequest(defaultInput)).rejects.toThrow(
|
||||
'TestConnection connection does not allow writes.'
|
||||
'Connection "testConnection" does not allow writes.'
|
||||
);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user