Database Layer for Compass Test Automation, implementing CTA-OSS Framework
This chapter describes the configuration for a DBLayer brick.
const config = {
'bricks': [
{
'name': 'mongodblayer',
'module': 'cta-dblayer',
'properties': {
'provider': 'mongodb',
'configuration': {
'url': 'mongodb://localhost:27017/cta',
}
},
'logger': {
'properties': {
'level': 'info',
},
},
'publish': [],
'subscribe':[],
},
],
}
const config = {
'bricks': [
{
'name': 'mongodblayer',
'module': 'cta-dblayer',
'properties': {
'provider': 'mongodb',
'configuration': {
'databaseName': 'cta',
'servers': [
{
'host': 'localhost',
'port': 27017,
},
],
'options': {},
}
},
'logger': {
'properties': {
'level': 'info',
},
},
'publish': [],
'subscribe':[],
},
],
}
Also pass custom collectionOptions
as options
argument to the db.collection() method
const config = {
'bricks': [
{
'name': 'mongodblayer',
'module': 'cta-dblayer',
'properties': {
'provider': 'mongodb',
'configuration': {
'databaseName': 'cta',
'servers': [
{
'host': 'localhost',
'port': 27017,
},
{
'host': 'localhost',
'port': 27018,
},
{
'host': 'localhost',
'port': 27019,
},
],
'options': {
'db': {
'w': 'majority',
'readPreference': 'primaryPreferred',
},
'replSet': {
'replicaSet': 'cta',
'poolSize': 5,
},
},
'collectionOptions': {
'strict': false,
}
}
},
'logger': {
'properties': {
'level': 'info',
},
},
'publish': [],
'subscribe':[],
},
],
}
Making operations to a Database is done by the DbLayer by sending a Job with a specific payload to it.
Find 10 documents in the collection user where name is "John"
const job = {
nature: {
type: 'database',
quality: 'query',
},
payload: {
collection: 'user',
action: 'find',
args: [
{ name: 'John' },
{ limit: 10 },
],
},
};
Group all user name by country and project the resulting docs as result.
user: { name:String, country:String }
result: { country:String, users:Array<user.name> }
const job = {
nature: {
type: 'database',
quality: 'query',
},
payload: {
collection: 'user',
action: 'aggregate',
args: [
[
{
$group: {
_id: '$country',
users: {
$addToSet: '$name',
},
},
},
{
$project: {
country: '$_id',
users: 1,
_id: 0,
},
},
],
],
},
};