diff --git a/.travis.yml b/.travis.yml index d98d2516d..96aad897b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,8 @@ services: script: # Audit npm packages. Fail build whan a PR audit fails, otherwise report the vulnerability and proceed. - - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --low; else npx audit-ci --low || true; fi + # see https://www.npmjs.com/advisories/1523 and https://github.com/lodash/lodash/pull/4759 discussion + - if [ "${TRAVIS_PULL_REQUEST}" != "false" ]; then npx audit-ci --low -a 1523; else npx audit-ci --low -a 1523 || true; fi - npm run lint - npm test - npm run test:apollo:default diff --git a/app/apollo/models/channel.schema.js b/app/apollo/models/channel.schema.js index 1ef4acf16..d846d57e9 100644 --- a/app/apollo/models/channel.schema.js +++ b/app/apollo/models/channel.schema.js @@ -22,6 +22,7 @@ const ChannelSchema = new mongoose.Schema({ }, org_id: { type: String, + alias: 'orgId', }, name: { type: String, diff --git a/app/apollo/models/cluster.js b/app/apollo/models/cluster.js index 65868b2ad..4587b6dda 100644 --- a/app/apollo/models/cluster.js +++ b/app/apollo/models/cluster.js @@ -16,7 +16,9 @@ const mongoose = require('mongoose'); const ClusterSchema = require('./cluster.schema'); +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); +ClusterSchema.plugin(mongooseLeanVirtuals); const Cluster = mongoose.model('clusters', ClusterSchema); module.exports = Cluster; diff --git a/app/apollo/models/cluster.schema.js b/app/apollo/models/cluster.schema.js index 16d5eeaf0..02cd0fb31 100644 --- a/app/apollo/models/cluster.schema.js +++ b/app/apollo/models/cluster.schema.js @@ -19,9 +19,11 @@ const { CLUSTER_REG_STATES } = require('./const'); const ClusterSchema = new mongoose.Schema({ org_id: { type: String, + alias: 'orgId', }, cluster_id: { type: String, + alias: 'clusterId', }, groups: [ { @@ -68,6 +70,7 @@ const ClusterSchema = new mongoose.Schema({ { user_id: { type: String, + alias: 'userId', }, content: { type: String, @@ -85,7 +88,8 @@ const ClusterSchema = new mongoose.Schema({ reg_state: { type: String, enum: [CLUSTER_REG_STATES.REGISTERING, CLUSTER_REG_STATES.PENDING, CLUSTER_REG_STATES.REGISTERED], - default: CLUSTER_REG_STATES.REGISTERING, + default: CLUSTER_REG_STATES.REGISTERING, + alias: 'regState', }, dirty: { diff --git a/app/apollo/models/deployableVersion.schema.js b/app/apollo/models/deployableVersion.schema.js index 88413769a..9184bf850 100644 --- a/app/apollo/models/deployableVersion.schema.js +++ b/app/apollo/models/deployableVersion.schema.js @@ -22,12 +22,15 @@ const DeployableVersionSchema = new mongoose.Schema({ }, org_id: { type: String, + alias: 'orgId', }, channel_id: { type: String, + alias: 'channelId', }, channel_name: { type: String, + alias: 'channelName', }, name: { type: String, diff --git a/app/apollo/models/group.js b/app/apollo/models/group.js index 93e78dec3..c88e0e761 100644 --- a/app/apollo/models/group.js +++ b/app/apollo/models/group.js @@ -16,7 +16,9 @@ const mongoose = require('mongoose'); const GroupSchema = require('./group.schema'); +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); +GroupSchema.plugin(mongooseLeanVirtuals); const Group = mongoose.model('groups', GroupSchema); module.exports = Group; diff --git a/app/apollo/models/group.schema.js b/app/apollo/models/group.schema.js index 953f46e91..0452f4245 100644 --- a/app/apollo/models/group.schema.js +++ b/app/apollo/models/group.schema.js @@ -23,6 +23,7 @@ const GroupSchema = new mongoose.Schema({ }, org_id: { type: String, + alias: 'orgId', }, name: { type: String, diff --git a/app/apollo/models/organization.default.schema.js b/app/apollo/models/organization.default.schema.js index 983a2cd11..09845669a 100644 --- a/app/apollo/models/organization.default.schema.js +++ b/app/apollo/models/organization.default.schema.js @@ -19,6 +19,7 @@ const { v4: uuid } = require('uuid'); const OrganizationDefaultSchema = new mongoose.Schema({ _id: { type: String, + alias: 'id', }, name: { type: String, diff --git a/app/apollo/models/organization.js b/app/apollo/models/organization.js index be42e4569..f2b7c6235 100644 --- a/app/apollo/models/organization.js +++ b/app/apollo/models/organization.js @@ -14,11 +14,12 @@ * limitations under the License. */ const mongoose = require('mongoose'); - +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); const { AUTH_MODEL } = require('./const'); const OrganizationSchema = require(`./organization.${AUTH_MODEL}.schema`); +OrganizationSchema.plugin(mongooseLeanVirtuals); const Organization = mongoose.model('orgs', OrganizationSchema); module.exports = Organization; diff --git a/app/apollo/models/organization.local.schema.js b/app/apollo/models/organization.local.schema.js index 39da9eab3..79a1d1bd7 100644 --- a/app/apollo/models/organization.local.schema.js +++ b/app/apollo/models/organization.local.schema.js @@ -19,6 +19,7 @@ const { v4: uuid } = require('uuid'); const OrganizationLocalSchema = new mongoose.Schema({ _id: { type: String, + alias: 'id', }, name: { type: String, diff --git a/app/apollo/models/resource.js b/app/apollo/models/resource.js index 4da27ec77..4c580164d 100644 --- a/app/apollo/models/resource.js +++ b/app/apollo/models/resource.js @@ -16,7 +16,9 @@ const mongoose = require('mongoose'); const ResourceSchema = require('./resource.schema'); +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); +ResourceSchema.plugin(mongooseLeanVirtuals); const Resource = mongoose.model('resources', ResourceSchema); module.exports = Resource; diff --git a/app/apollo/models/resource.schema.js b/app/apollo/models/resource.schema.js index 8c963e3e2..5d79831f4 100644 --- a/app/apollo/models/resource.schema.js +++ b/app/apollo/models/resource.schema.js @@ -19,9 +19,11 @@ const mongoose = require('mongoose'); const ResourceSchema = new mongoose.Schema({ org_id: { type: String, + alias: 'orgId', }, cluster_id: { type: String, + alias: 'clusterId', }, selfLink: { type: String, diff --git a/app/apollo/models/resourceYamlHist.js b/app/apollo/models/resourceYamlHist.js index a938b0982..c2d168452 100644 --- a/app/apollo/models/resourceYamlHist.js +++ b/app/apollo/models/resourceYamlHist.js @@ -16,7 +16,9 @@ const mongoose = require('mongoose'); const ResourceYamlHistSchema = require('./resourceYamlHist.schema'); +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); +ResourceYamlHistSchema.plugin(mongooseLeanVirtuals); const ResourceYamlHist = mongoose.model('resourceYamlHist', ResourceYamlHistSchema, 'resourceYamlHist'); module.exports = ResourceYamlHist; diff --git a/app/apollo/models/resourceYamlHist.schema.js b/app/apollo/models/resourceYamlHist.schema.js index 571552566..463766d56 100644 --- a/app/apollo/models/resourceYamlHist.schema.js +++ b/app/apollo/models/resourceYamlHist.schema.js @@ -19,6 +19,7 @@ const mongoose = require('mongoose'); const ResourceYamlHistSchema = new mongoose.Schema({ _id:{ type: String, + alias: 'id', }, org_id: { type: String, diff --git a/app/apollo/models/subscription.js b/app/apollo/models/subscription.js index 3bbbf7e00..248d7c3dd 100644 --- a/app/apollo/models/subscription.js +++ b/app/apollo/models/subscription.js @@ -16,7 +16,9 @@ const mongoose = require('mongoose'); const SubscriptionSchema = require('./subscription.schema'); +const mongooseLeanVirtuals = require('mongoose-lean-virtuals'); +SubscriptionSchema.plugin(mongooseLeanVirtuals); const Subscription = mongoose.model('subscriptions', SubscriptionSchema); module.exports = Subscription; diff --git a/app/apollo/models/subscription.schema.js b/app/apollo/models/subscription.schema.js index 22d3dd261..55f89ee8e 100644 --- a/app/apollo/models/subscription.schema.js +++ b/app/apollo/models/subscription.schema.js @@ -22,6 +22,7 @@ const SubscriptionSchema = new mongoose.Schema({ }, org_id: { type: String, + alias: 'orgId', }, name: { type: String, @@ -36,6 +37,7 @@ const SubscriptionSchema = new mongoose.Schema({ ], channel_uuid: { type: String, + alias: 'channelUuid', }, channel: { type: String, @@ -45,6 +47,7 @@ const SubscriptionSchema = new mongoose.Schema({ }, version_uuid: { type: String, + alias: 'versionUuid', }, owner: { type: String, diff --git a/app/apollo/models/user.default.schema.js b/app/apollo/models/user.default.schema.js index 34899ffb9..54ae38bc1 100644 --- a/app/apollo/models/user.default.schema.js +++ b/app/apollo/models/user.default.schema.js @@ -159,7 +159,7 @@ UserDefaultSchema.statics.getOrgs = async function(context) { // of the github|bitbucket orgs a user belongs to, find ones that are registered in razee const orgFromDB = await models.Organization.findOne({ gheOrgId: org.gheOrgId }).lean(); if (orgFromDB) { - results.push({ name: orgFromDB.name, _id: orgFromDB._id }); + results.push({ name: orgFromDB.name, id: orgFromDB._id }); } } } @@ -171,7 +171,7 @@ UserDefaultSchema.statics.getOrgById = async function(models, orgId) { }; UserDefaultSchema.statics.getOrg = async function(models, me) { - return await models.Organization.findOne({ orgKeys: me.orgKey }).lean(); + return await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true }); }; UserDefaultSchema.statics.getBasicUsersByIds = async function(ids){ @@ -180,15 +180,15 @@ UserDefaultSchema.statics.getBasicUsersByIds = async function(ids){ } var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 }); users = users.map((user)=>{ - var _id = user._id; - var name = _.get(user, 'profile.name') || _.get(user, 'service.default.username') || _id; + var id = user._id; + var name = _.get(user, 'profile.name') || _.get(user, 'service.default.username') || id; return { - _id, + id, name, }; }); - users = _.keyBy(users, '_id'); - users['undefined'] = {_id: 'undefined', name: 'undefined'}; + users = _.keyBy(users, 'id'); + users['undefined'] = {id: 'undefined', name: 'undefined'}; return users; }; diff --git a/app/apollo/models/user.local.schema.js b/app/apollo/models/user.local.schema.js index 4c93d4d18..0034bb49a 100644 --- a/app/apollo/models/user.local.schema.js +++ b/app/apollo/models/user.local.schema.js @@ -84,7 +84,7 @@ const UserLocalSchema = new mongoose.Schema({ }); async function getOrCreateOrganization(models, args) { - const orgName = args.org_name || 'default_local_org'; + const orgName = args.orgName || 'default_local_org'; const org = await models.Organization.findOne({ name: orgName }); if (org) return org; if (models.OrganizationDistributed) { @@ -160,13 +160,17 @@ UserLocalSchema.statics.createToken = async (user, secret, expiresIn) => { UserLocalSchema.statics.getCurrentUser = ({me , req_id, logger}) => { let result = me; + let data = me.meta.orgs[0]; + data.id = data._id; + delete(data._id); + if (result != null) { result = { type: me.type, id: me._id, email: me.email, identifier: me.identifier, - org_id: me.org_id, + orgId: me.org_id, role: me.role, meta: me.meta, }; @@ -319,7 +323,7 @@ UserLocalSchema.statics.isAuthorized = async function(me, orgId, action, type, a UserLocalSchema.statics.getOrg = async function(models, me) { let org; - org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean(); + org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true }); return org; }; @@ -333,7 +337,7 @@ UserLocalSchema.statics.getOrgs = async function(context) { // eslint-disable-next-line no-await-in-loop const orgFromDB = await models.Organization.findOne({ _id: org._id }); if (orgFromDB) { - results.push({ name: orgFromDB.name, _id: org._id }); + results.push({ name: orgFromDB.name, id: org._id }); } } } @@ -346,15 +350,15 @@ UserLocalSchema.statics.getBasicUsersByIds = async function(ids){ } var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 }); users = users.map((user)=>{ - var _id = user._id; - var name = _.get(user, 'profile.name') || _.get(user, 'services.local.username') || _id; + var id = user._id; + var name = _.get(user, 'profile.name') || _.get(user, 'services.local.username') || id; return { - _id, + id, name, }; }); - users = _.keyBy(users, '_id'); - users['undefined'] = {_id: 'undefined', name: 'undefined'}; + users = _.keyBy(users, 'id'); + users['undefined'] = {id: 'undefined', name: 'undefined'}; return users; }; diff --git a/app/apollo/models/user.passport.local.schema.js b/app/apollo/models/user.passport.local.schema.js index e5cae0a78..9a63ff550 100644 --- a/app/apollo/models/user.passport.local.schema.js +++ b/app/apollo/models/user.passport.local.schema.js @@ -85,7 +85,7 @@ const UserPassportLocalSchema = new mongoose.Schema({ }); async function getOrCreateOrganization(models, args) { - const orgName = args.org_name || 'default_local_org'; + const orgName = args.orgName || 'default_local_org'; const org = await models.Organization.findOne({ name: orgName }); if (org) return org; if (models.OrganizationDistributed) { @@ -165,13 +165,17 @@ UserPassportLocalSchema.statics.createToken = async ( UserPassportLocalSchema.statics.getCurrentUser = ({me , req_id, logger}) => { let result = me; + let data = me.meta.orgs[0]; + data.id = data._id; + delete(data._id); + if (result != null) { result = { type: me.type, id: me._id, email: me.email, identifier: me.identifier, - org_id: me.org_id, + orgId: me.org_id, role: me.role, meta: me.meta, }; @@ -325,7 +329,7 @@ UserPassportLocalSchema.statics.isAuthorized = async function(me, orgId, action, UserPassportLocalSchema.statics.getOrg = async function(models, me) { let org; - org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean(); + org = await models.Organization.findOne({ orgKeys: me.orgKey }).lean({ virtuals: true }); return org; }; @@ -339,7 +343,7 @@ UserPassportLocalSchema.statics.getOrgs = async function(context) { // eslint-disable-next-line no-await-in-loop const orgFromDB = await models.Organization.findOne({ _id: org._id }); if (orgFromDB) { - results.push({ name: orgFromDB.name, _id: org._id }); + results.push({ name: orgFromDB.name, id: org._id }); } } } @@ -352,15 +356,15 @@ UserPassportLocalSchema.statics.getBasicUsersByIds = async function(ids){ } var users = await this.find({ _id: { $in: ids } }, { }, { lean: 1 }); users = users.map((user)=>{ - var _id = user._id; - var name = _.get(user, 'profile.name') || _.get(user, 'services.passportlocal.username') || _id; + var id = user._id; + var name = _.get(user, 'profile.name') || _.get(user, 'services.passportlocal.username') || id; return { - _id, + id, name, }; }); - users = _.keyBy(users, '_id'); - users['undefined'] = {_id: 'undefined', name: 'undefined'}; + users = _.keyBy(users, 'id'); + users['undefined'] = {id: 'undefined', name: 'undefined'}; return users; }; diff --git a/app/apollo/resolvers/channel.js b/app/apollo/resolvers/channel.js index 7e05fc148..ff0b265cf 100644 --- a/app/apollo/resolvers/channel.js +++ b/app/apollo/resolvers/channel.js @@ -30,7 +30,7 @@ const { encryptOrgData, decryptOrgData} = require('../../utils/orgs'); const channelResolvers = { Query: { - channels: async(parent, { org_id }, context) => { + channels: async(parent, { orgId: org_id }, context) => { const { models, me, req_id, logger } = context; const queryName = 'channels'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -44,7 +44,7 @@ const channelResolvers = { } return channels; }, - channel: async(parent, { org_id, uuid }, context) => { + channel: async(parent, { orgId: org_id, uuid }, context) => { const { models, me, req_id, logger } = context; const queryName = 'channel'; logger.debug({req_id, user: whoIs(me), org_id, uuid}, `${queryName} enter`); @@ -58,7 +58,7 @@ const channelResolvers = { } return channel; }, - getChannelVersion: async(parent, { org_id, channel_uuid, version_uuid }, context) => { + getChannelVersion: async(parent, { orgId: org_id, channelUuid: channel_uuid, versionUuid: version_uuid }, context) => { const { models, me, req_id, logger } = context; const queryName = 'getChannelVersion'; logger.debug({req_id, user: whoIs(me), org_id, channel_uuid, version_uuid }, `${queryName} enter`); @@ -108,7 +108,7 @@ const channelResolvers = { } }, Mutation: { - addChannel: async (parent, { org_id, name }, context)=>{ + addChannel: async (parent, { orgId: org_id, name }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'addChannel'; logger.debug({ req_id, user: whoIs(me), org_id, name }, `${queryName} enter`); @@ -133,7 +133,7 @@ const channelResolvers = { throw err; } }, - editChannel: async (parent, { org_id, uuid, name }, context)=>{ + editChannel: async (parent, { orgId: org_id, uuid, name }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'editChannel'; logger.debug({ req_id, user: whoIs(me), org_id, uuid, name }, `${queryName} enter`); @@ -157,7 +157,7 @@ const channelResolvers = { throw err; } }, - addChannelVersion: async(parent, { org_id, channel_uuid, name, type, content, file, description }, context)=>{ + addChannelVersion: async(parent, { orgId: org_id, channelUuid: channel_uuid, name, type, content, file, description }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'addChannelVersion'; @@ -268,10 +268,10 @@ const channelResolvers = { ); return { success: true, - version_uuid: versionObj.uuid, + versionUuid: versionObj.uuid, }; }, - removeChannel: async (parent, { org_id, uuid }, context)=>{ + removeChannel: async (parent, { orgId: org_id, uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'removeChannel'; logger.debug({ req_id, user: whoIs(me), org_id, uuid }, `${queryName} enter`); @@ -301,7 +301,7 @@ const channelResolvers = { throw err; } }, - removeChannelVersion: async (parent, { org_id, uuid }, context)=>{ + removeChannelVersion: async (parent, { orgId: org_id, uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'removeChannelVersion'; logger.debug({ req_id, user: whoIs(me), org_id, uuid }, `${queryName} enter`); diff --git a/app/apollo/resolvers/cluster.js b/app/apollo/resolvers/cluster.js index a6e4f821d..6e06903b9 100644 --- a/app/apollo/resolvers/cluster.js +++ b/app/apollo/resolvers/cluster.js @@ -59,18 +59,18 @@ const commonClusterSearch = async ( results = await models.Cluster.find(searchFilter) .sort({ _id: -1 }) .limit(limit) - .lean(); + .lean({ virtuals: true }); return results; }; const clusterResolvers = { Query: { - clusterByClusterID: async ( + clusterByClusterId: async ( parent, - { org_id: orgId, cluster_id: clusterId }, + { orgId, clusterId }, context, ) => { - const queryName = 'clusterByClusterID'; + const queryName = 'clusterByClusterId'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), orgId, clusterId}, `${queryName} enter`); @@ -81,7 +81,7 @@ const clusterResolvers = { org_id: orgId, cluster_id: clusterId, ...conditions - }).lean(); + }).lean({ virtuals: true }); var { url } = await models.Organization.getRegistrationUrl(orgId, context); url = url + `&clusterId=${clusterId}`; @@ -101,12 +101,12 @@ const clusterResolvers = { // - limit: number of docs to return. default 50, 0 means return all // - startingAfter: for pagination. Specify the _id of the document you want results // older than. - clustersByOrgID: async ( + clustersByOrgId: async ( parent, - { org_id: orgId, limit, startingAfter }, + { orgId, limit, startingAfter }, context, ) => { - const queryName = 'clustersByOrgID'; + const queryName = 'clustersByOrgId'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), orgId, limit, startingAfter}, `${queryName} enter`); @@ -120,7 +120,7 @@ const clusterResolvers = { // Find all the clusters that have not been updated in the last day clusterZombies: async ( parent, - { org_id: orgId, limit }, + { orgId, limit }, context, ) => { const queryName = 'clusterZombies'; @@ -140,14 +140,14 @@ const clusterResolvers = { clusterSearch: async ( parent, - { org_id: orgId, filter, limit }, + { orgId, filter, limit }, context, ) => { const queryName = 'clusterSearch'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), orgId, filter, limit}, `${queryName} enter`); - // first get all users permitted cluster groups, + // first get all users permitted cluster groups, await validAuth(me, orgId, ACTIONS.READ, TYPES.CLUSTER, queryName, context); const conditions = await getGroupConditionsIncludingEmpty(me, orgId, ACTIONS.READ, 'uuid', queryName, context); @@ -170,7 +170,7 @@ const clusterResolvers = { // Active means the cluster information has been updated in the last day clusterCountByKubeVersion: async ( parent, - { org_id: orgId }, + { orgId }, context, ) => { const queryName = 'clusterCountByKubeVersion'; @@ -200,17 +200,18 @@ const clusterResolvers = { { $sort: { _id: 1 } }, ]); + for (const item of results){ item.id = item._id; } return results; }, // end clusterCountByKubeVersion }, // end query Mutation: { - deleteClusterByClusterID: async ( + deleteClusterByClusterId: async ( parent, - { org_id, cluster_id }, + { orgId: org_id, clusterId: cluster_id }, context, ) => { - const queryName = 'deleteClusterByClusterID'; + const queryName = 'deleteClusterByClusterId'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), org_id, cluster_id}, `${queryName} enter`); @@ -222,7 +223,7 @@ const clusterResolvers = { //TODO: soft delete the resources for now. We need to have a background process to // clean up S3 contents based on deleted flag. - const deletedResources = await models.Resource.updateMany({ org_id, cluster_id }, + const deletedResources = await models.Resource.updateMany({ org_id, cluster_id }, {$set: { deleted: true }}, { upsert: false }); logger.debug({req_id, user: whoIs(me), org_id, cluster_id, deletedResources, deletedCluster}, `${queryName} results are`); @@ -238,7 +239,7 @@ const clusterResolvers = { deleteClusters: async ( parent, - { org_id }, + { orgId: org_id }, context, ) => { const queryName = 'deleteClusters'; @@ -266,7 +267,7 @@ const clusterResolvers = { } }, // end delete cluster by org_id - registerCluster: async (parent, { org_id, registration }, context) => { + registerCluster: async (parent, { orgId: org_id, registration }, context) => { const queryName = 'registerCluster'; const { models, me, req_id, logger } = context; logger.debug({ req_id, user: whoIs(me), org_id, registration }, `${queryName} enter`); @@ -317,7 +318,7 @@ const clusterResolvers = { url += `&args=${arg}`; }); } - return { url, org_id: org_id, clusterId: cluster_id, orgKey: org.orgKeys[0], regState: reg_state, registration }; + return { url, orgId: org_id, clusterId: cluster_id, orgKey: org.orgKeys[0], regState: reg_state, registration }; } catch (error) { logger.error({ req_id, user: whoIs(me), org_id, error }, `${queryName} error encountered`); throw error; diff --git a/app/apollo/resolvers/clusterDistributed.js b/app/apollo/resolvers/clusterDistributed.js index cecf04847..237078182 100644 --- a/app/apollo/resolvers/clusterDistributed.js +++ b/app/apollo/resolvers/clusterDistributed.js @@ -64,7 +64,7 @@ const commonClusterDistributedSearch = async ( ); resultsArray.map(resultSet => { return resultSet.map(result => { - return results.push(result.toJSON()); + return results.push(result.toJSON({ virtuals: true })); }); }); } catch (error) { @@ -79,12 +79,12 @@ const commonClusterDistributedSearch = async ( const clusterDistributedResolvers = { Query: { - clusterDistributedByClusterID: async ( + clusterDistributedByClusterId: async ( parent, - { org_id: orgId, cluster_id: clusterId }, + { orgId: orgId, clusterId: clusterId }, context, ) => { - const queryName = 'clusterDistributedByClusterID'; + const queryName = 'clusterDistributedByClusterId'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), orgId, clusterId}, `${queryName} enter`); @@ -101,18 +101,18 @@ const clusterDistributedResolvers = { }); if (result != null) { - return result.toJSON(); + return result.toJSON({ virtuals: true }); } } return null; - }, // end clusterDistributedByClusterID + }, // end clusterDistributedByClusterId - clustersDistributedByOrgID: async ( + clustersDistributedByOrgId: async ( parent, - { org_id: orgId, limit }, + { orgId: orgId, limit }, context, ) => { - const queryName = 'clustersDistributedByOrgID'; + const queryName = 'clustersDistributedByOrgId'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), orgId, limit}, `${queryName} enter`); @@ -126,12 +126,12 @@ const clusterDistributedResolvers = { logger, queryName, ); - }, // end clustersDistributedByOrgID + }, // end clustersDistributedByOrgId // Find all the clusters that have not been updated in the last day clusterDistributedZombies: async ( parent, - { org_id: orgId, limit }, + { orgId: orgId, limit }, context, ) => { const queryName = 'clusterDistributedZombies'; @@ -158,7 +158,7 @@ const clusterDistributedResolvers = { clusterDistributedSearch: async ( parent, - { org_id: orgId, filter, limit = 50 }, + { orgId: orgId, filter, limit = 50 }, context, ) => { const queryName = 'clusterDistributedSearch'; @@ -194,7 +194,7 @@ const clusterDistributedResolvers = { // Active means the cluster information has been updated in the last day clusterDistributedCountByKubeVersion: async ( parent, - { org_id: orgId }, + { orgId: orgId }, context, ) => { const queryName = 'clusterDistributedCountByKubeVersion'; @@ -259,6 +259,7 @@ const clusterDistributedResolvers = { } } logger.debug(`${queryName} totalResults: ${JSON.stringify(totalResults, null, 4)} for req_id ${req_id}`); + for (const item of totalResults){ item.id = item._id; } return totalResults; }, // end clusterDistributedCountByKubeVersion }, // end query diff --git a/app/apollo/resolvers/group.js b/app/apollo/resolvers/group.js index 025b80f2d..48d030dbd 100644 --- a/app/apollo/resolvers/group.js +++ b/app/apollo/resolvers/group.js @@ -26,14 +26,14 @@ const pubSub = GraphqlPubSub.getInstance(); const groupResolvers = { Query: { - groups: async(parent, { org_id }, context) => { + groups: async(parent, { orgId: org_id }, context) => { const { models, me, req_id, logger } = context; const queryName = 'groups'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); await validAuth(me, org_id, ACTIONS.READ, TYPES.GROUP, queryName, context); let groups; try{ - groups = await models.Group.find({ org_id: org_id }).lean(); + groups = await models.Group.find({ org_id: org_id }).lean({ virtuals: true }); const ownerIds = _.map(groups, 'owner'); const owners = await models.User.getBasicUsersByIds(ownerIds); @@ -47,14 +47,14 @@ const groupResolvers = { } return groups; }, - group: async(parent, { org_id: org_id, uuid }, context) => { + group: async(parent, { orgId: org_id, uuid }, context) => { const { models, me, req_id, logger } = context; const queryName = 'group'; logger.debug({req_id, user: whoIs(me), org_id, uuid}, `${queryName} enter`); await validAuth(me, org_id, ACTIONS.READ, TYPES.GROUP, queryName, context); try{ - let group = await models.Group.findOne({ org_id: org_id, uuid }).lean(); + let group = await models.Group.findOne({ org_id: org_id, uuid }).lean({ virtuals: true }); if (!group) { throw new NotFoundError(`could not find group with uuid ${uuid}.`); } @@ -67,7 +67,7 @@ const groupResolvers = { groups: group.name, }, }, - { $project: { name: 1, uuid: 1, groups: 1, version: 1, channel: 1 , org_id: 1, channel_uuid: 1, version_uuid: 1, owner: 1, created: 1, updated: 1 } }, + { $project: { _id: 0, name: 1, uuid: 1, groups: 1, version: 1, channel: 1 , orgId: '$org_id', channelUuid: '$channel_uuid', versionUuid: '$version_uuid', owner: 1, created: 1, updated: 1 } }, ]); const clusterCount = await models.Cluster.count({ org_id: org_id, 'groups.uuid': group.uuid }); const clusters = await models.Cluster.aggregate([ @@ -77,7 +77,7 @@ const groupResolvers = { 'groups.uuid': group.uuid, }, }, - { $project: { cluster_id: 1, groups: 1, registration: 1, reg_state: 1, org_id: 1, created: 1, updated: 1 } }, + { $project: { _id: 0, clusterId: '$cluster_id', 'groups.uuid': 1, 'groups.name': 1, registration: 1, regState: '$reg_state', orgId: '$org_id', created: 1, updated: 1 } }, ]); group.owner = owners[group.owner]; @@ -87,14 +87,14 @@ const groupResolvers = { throw err; } }, - groupByName: async(parent, { org_id, name }, context) => { + groupByName: async(parent, { orgId: org_id, name }, context) => { const { models, me, req_id, logger } = context; const queryName = 'groupByName'; logger.debug({req_id, user: whoIs(me), org_id, name}, `${queryName} enter`); await validAuth(me, org_id, ACTIONS.READ, TYPES.GROUP, queryName, context); try{ - let group = await models.Group.findOne({ org_id: org_id, name }).lean(); + let group = await models.Group.findOne({ org_id: org_id, name }).lean({ virtuals: true }); if (!group) { throw new NotFoundError(`could not find group with name ${name}.`); } @@ -107,7 +107,7 @@ const groupResolvers = { groups: group.name, }, }, - { $project: { name: 1, uuid: 1, groups: 1, version: 1, channel: 1 , org_id: 1, channel_uuid: 1, version_uuid: 1, owner: 1, created: 1, updated: 1 } }, + { $project: { _id: 0, name: 1, uuid: 1, groups: 1, version: 1, channel: 1 , orgId: '$org_id', channelUuid: '$channel_uuid', versionUuid: '$version_uuid', owner: 1, created: 1, updated: 1 } }, ]); const clusterCount = await models.Cluster.count({ org_id: org_id, 'groups.uuid': group.uuid }); const clusters = await models.Cluster.aggregate([ @@ -117,7 +117,7 @@ const groupResolvers = { 'groups.uuid': group.uuid, }, }, - { $project: { cluster_id: 1, groups: 1, registration: 1, reg_state: 1, org_id: 1, created: 1, updated: 1 } }, + { $project: { _id: 0, clusterId: '$cluster_id', 'groups.uuid': 1, 'groups.name': 1, registration: 1, regState: '$reg_state', orgId: '$org_id', created: 1, updated: 1 } }, ]); group.owner = owners[group.owner]; @@ -129,7 +129,7 @@ const groupResolvers = { }, }, Mutation: { - addGroup: async (parent, { org_id, name }, context)=>{ + addGroup: async (parent, { orgId: org_id, name }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'addGroup'; logger.debug({ req_id, user: whoIs(me), org_id, name }, `${queryName} enter`); @@ -158,7 +158,7 @@ const groupResolvers = { } }, - removeGroup: async (parent, { org_id, uuid }, context)=>{ + removeGroup: async (parent, { orgId: org_id, uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'removeGroup'; logger.debug({ req_id, user: whoIs(me), org_id, uuid }, `${queryName} enter`); @@ -195,7 +195,7 @@ const groupResolvers = { } }, - removeGroupByName: async (parent, { org_id, name }, context)=>{ + removeGroupByName: async (parent, { orgId: org_id, name }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'removeGroupByName'; logger.debug({ req_id, user: whoIs(me), org_id, name }, `${queryName} enter`); @@ -231,7 +231,7 @@ const groupResolvers = { } }, - groupClusters: async (parent, { org_id, uuid, clusters }, context)=>{ + groupClusters: async (parent, { orgId: org_id, uuid, clusters }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'groupClusters'; logger.debug({ req_id, user: whoIs(me), uuid, clusters }, `${queryName} enter`); @@ -260,7 +260,7 @@ const groupResolvers = { } }, - unGroupClusters: async (parent, { org_id, uuid, clusters }, context)=>{ + unGroupClusters: async (parent, { orgId: org_id, uuid, clusters }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'unGroupClusters'; logger.debug({ req_id, user: whoIs(me), uuid, clusters }, `${queryName} enter`); diff --git a/app/apollo/resolvers/organization.js b/app/apollo/resolvers/organization.js index 3e2a02619..4abcb438d 100644 --- a/app/apollo/resolvers/organization.js +++ b/app/apollo/resolvers/organization.js @@ -20,7 +20,7 @@ const { whoIs, validAuth } = require ('./common'); const organizationResolvers = { Query: { - registrationUrl: async (parent, { org_id }, context) => { + registrationUrl: async (parent, { orgId: org_id }, context) => { const queryName = 'registrationUrl'; const { models, me, req_id, logger } = context; logger.debug({req_id, org_id}, `${queryName} enter`); diff --git a/app/apollo/resolvers/resource.js b/app/apollo/resolvers/resource.js index 109b2370c..fe0640488 100644 --- a/app/apollo/resolvers/resource.js +++ b/app/apollo/resolvers/resource.js @@ -35,7 +35,7 @@ const commonResourcesSearch = async ({ context, org_id, searchFilter, limit=500, const resources = await models.Resource.find(searchFilter) .sort(sort) .limit(limit) - .lean() + .lean({ virtuals: true }) ; var count = await models.Resource.find(searchFilter).count(); // if user is requesting the cluster field (i.e cluster_id/name), then adds it to the results @@ -101,7 +101,7 @@ const commonResourceSearch = async ({ context, org_id, searchFilter, queryFields try { const conditions = await getGroupConditionsIncludingEmpty(me, org_id, ACTIONS.READ, 'uuid', 'resource.commonResourceSearch', context); - let resource = await models.Resource.findOne(searchFilter).lean(); + let resource = await models.Resource.findOne(searchFilter).lean({ virtuals: true }); if (!resource) return resource; @@ -144,7 +144,7 @@ const buildSortObj = (sortArr, allowedFields)=>{ const resourceResolvers = { Query: { - resourcesCount: async (parent, { org_id }, context) => { + resourcesCount: async (parent, { orgId: org_id }, context) => { const queryName = 'resourcesCount'; const { models, me, req_id, logger } = context; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -164,7 +164,7 @@ const resourceResolvers = { }, resources: async ( parent, - { org_id, filter, fromDate, toDate, limit, kinds = [], sort }, + { orgId: org_id, filter, fromDate, toDate, limit, kinds = [], sort }, context, fullQuery ) => { @@ -192,7 +192,7 @@ const resourceResolvers = { resourcesByCluster: async ( parent, - { org_id, cluster_id, filter, limit }, + { orgId: org_id, clusterId: cluster_id, filter, limit }, context, fullQuery ) => { @@ -220,7 +220,7 @@ const resourceResolvers = { return false; }); } - + let searchFilter = { org_id: org_id, cluster_id: cluster_id, @@ -233,7 +233,7 @@ const resourceResolvers = { return commonResourcesSearch({ context, org_id, searchFilter, limit, queryFields }); }, - resource: async (parent, { org_id, _id, histId }, context, fullQuery) => { + resource: async (parent, { orgId: org_id, id: _id, histId }, context, fullQuery) => { const queryFields = GraphqlFields(fullQuery); const queryName = 'resource'; const { models, me, req_id, logger } = context; @@ -257,7 +257,7 @@ const resourceResolvers = { resourceByKeys: async ( parent, - { org_id, cluster_id, selfLink }, + { orgId: org_id, clusterId: cluster_id, selfLink }, context, fullQuery ) => { @@ -273,7 +273,7 @@ const resourceResolvers = { return commonResourceSearch({ context, org_id, searchFilter, queryFields }); }, - resourcesBySubscription: async ( parent, { org_id, subscription_id}, context, fullQuery) => { + resourcesBySubscription: async ( parent, { orgId: org_id, subscriptionId: subscription_id}, context, fullQuery) => { const queryFields = GraphqlFields(fullQuery); const queryName = 'resourcesBySubscription'; const { me, models, req_id, logger } = context; @@ -300,7 +300,7 @@ const resourceResolvers = { return commonResourcesSearch({ context, org_id, searchFilter, queryFields }); }, - resourceHistory: async(parent, { org_id, cluster_id, resourceSelfLink, beforeDate, afterDate, limit }, context)=>{ + resourceHistory: async(parent, { orgId: org_id, clusterId: cluster_id, resourceSelfLink, beforeDate, afterDate, limit }, context)=>{ const { models, me, req_id, logger } = context; limit = _.clamp(limit, 1, 1000); @@ -323,7 +323,7 @@ const resourceResolvers = { searchObj.updated = updatedSearchObj; } - const histObjs = await models.ResourceYamlHist.find(searchObj, { _id:1, updated:1 }, { limit, lean: true }); + const histObjs = await models.ResourceYamlHist.find(searchObj, { _id:1, updated:1 }, { limit }).lean({ virtuals: true }); const count = await models.ResourceYamlHist.find(searchObj).count(); return { @@ -332,7 +332,7 @@ const resourceResolvers = { }; }, - resourceContent: async(parent, { org_id, cluster_id, resourceSelfLink, histId=null }, context)=>{ + resourceContent: async(parent, { orgId: org_id, clusterId: cluster_id, resourceSelfLink, histId=null }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'resourceContent'; @@ -347,7 +347,7 @@ const resourceResolvers = { if(!histId || histId == resource._id.toString()){ let content = await getContent(resource); return { - _id: resource._id, + id: resource._id, content, updated: resource.updated, }; @@ -361,7 +361,7 @@ const resourceResolvers = { const content = await getContent(obj); return { - _id: obj._id, + id: obj._id, content, updated: obj.updated, }; @@ -369,7 +369,7 @@ const resourceResolvers = { }, Subscription: { resourceUpdated: { - resolve: (parent, { org_id, filter }, { models, me, req_id, logger }) => { + resolve: (parent, { orgID: org_id, filter }, { models, me, req_id, logger }) => { logger.debug( { modelKeys: Object.keys(models), org_id, filter, me, req_id }, 'Subscription.resourceUpdated.resolve', @@ -381,7 +381,7 @@ const resourceResolvers = { subscribe: withFilter( // eslint-disable-next-line no-unused-vars (parent, args, context) => { - const topic = getStreamingTopic(EVENTS.RESOURCE.UPDATED, args.org_id); + const topic = getStreamingTopic(EVENTS.RESOURCE.UPDATED, args.orgId); context.logger.debug({args, me: context.me, topic}, 'withFilter asyncIteratorFn'); // TODO: in future probably we should valid authorization here return GraphqlPubSub.getInstance().pubSub.asyncIterator(topic); @@ -392,10 +392,10 @@ const resourceResolvers = { logger.debug( {req_id, user: whoIs(me), args }, `${queryName}: context.keys: [${Object.keys(context)}]`, ); - await validAuth(me, args.org_id, ACTIONS.READ, TYPES.RESOURCE, queryName, context); + await validAuth(me, args.orgId, ACTIONS.READ, TYPES.RESOURCE, queryName, context); let found = true; const { resource } = parent.resourceUpdated; - if (args.org_id !== resource.org_id) { + if (args.orgId !== resource.orgId) { return false; } if (args.filter && args.filter !== '') { @@ -403,7 +403,7 @@ const resourceResolvers = { // eslint-disable-next-line no-restricted-syntax for (const token of tokens) { if ( - resource.cluster_id.match(token) || + resource.clusterId.match(token) || resource.selfLink.match(token) || (resource.searchableData.kind && resource.searchableData.kind.match(token)) || diff --git a/app/apollo/resolvers/resourceDistributed.js b/app/apollo/resolvers/resourceDistributed.js index 587bebc69..0226c687d 100644 --- a/app/apollo/resolvers/resourceDistributed.js +++ b/app/apollo/resolvers/resourceDistributed.js @@ -34,7 +34,7 @@ const commonResourcesDistributedSearch = async ( .find(searchFilter) .sort({ created: -1 }) .limit(limit) - .lean(); + .lean({ virtuals: true }); }), ); resultsArray.map(rs => { @@ -53,7 +53,7 @@ const resourceDistributedResolvers = { Query: { resourcesDistributedCount: async ( parent, - { org_id }, + { orgId: org_id }, context, ) => { const queryName = 'resourcesDistributedCount'; @@ -84,7 +84,7 @@ const resourceDistributedResolvers = { resourcesDistributed: async ( parent, - { org_id, filter, fromDate, toDate, limit }, + { orgId: org_id, filter, fromDate, toDate, limit }, context, ) => { const queryName = 'resourcesDistributed'; @@ -115,7 +115,7 @@ const resourceDistributedResolvers = { resourcesDistributedByCluster: async ( parent, - { org_id, cluster_id, filter, limit }, + { orgId: org_id, clusterId: cluster_id, filter, limit }, context, ) => { const queryName = 'resourcesDistributedByCluster'; @@ -143,14 +143,14 @@ const resourceDistributedResolvers = { ); }, - resourceDistributed: async (parent, { _id }, context) => { + resourceDistributed: async (parent, { id: _id }, context) => { const queryName = 'resourceDistributed'; const { models, me, req_id, logger } = context; logger.debug( {req_id, user: whoIs(me), _id }, `${queryName} enter`); // eslint-disable-next-line no-restricted-syntax for (const rd of models.ResourceDistributed) { // eslint-disable-next-line no-await-in-loop - let result = await rd.findById(_id).lean(); + let result = await rd.findById(_id).lean({ virtuals: true }); if (result !== null) { // eslint-disable-next-line no-await-in-loop await validAuth(me, result.org_id, ACTIONS.READ, TYPES.RESOURCE, queryName, context); @@ -162,7 +162,7 @@ const resourceDistributedResolvers = { resourceDistributedByKeys: async ( parent, - { org_id, cluster_id, selfLink }, + { orgId: org_id, clusterId: cluster_id, selfLink }, context, ) => { const queryName = 'resourceDistributedByKeys'; @@ -172,7 +172,7 @@ const resourceDistributedResolvers = { // eslint-disable-next-line no-restricted-syntax for (const rd of models.ResourceDistributed) { // eslint-disable-next-line no-await-in-loop - let result = await rd.findOne({ org_id, cluster_id, selfLink }).lean(); + let result = await rd.findOne({ org_id, cluster_id, selfLink }).lean({ virtuals: true }); if (result !== null) { return result; } diff --git a/app/apollo/resolvers/subscription.js b/app/apollo/resolvers/subscription.js index 9880f2db5..f33374ec5 100644 --- a/app/apollo/resolvers/subscription.js +++ b/app/apollo/resolvers/subscription.js @@ -45,11 +45,16 @@ async function validateGroups(org_id, groups, context) { const subscriptionResolvers = { Query: { - // Cluster-facing API - subscriptionsByCluster: async(parent, { cluster_id, /* may add some unique data from the cluster later for verification. */ }, context) => { + // Cluster-facing API, deprecated, + subscriptionsByCluster: async(parent, { cluster_id }, context) => { + return await subscriptionResolvers.Query.subscriptionsByClusterId(parent, {clusterId: cluster_id, deprecated: true}, context); + }, + + // Cluster-facing API, + subscriptionsByClusterId: async(parent, { clusterId: cluster_id, deprecated /* may add some unique data from the cluster later for verification. */ }, context) => { const { req_id, me, models, logger } = context; - const query = 'subscriptionsByCluster'; - logger.debug({req_id, user: whoIs(me), cluster_id}, `${query} enter`); + const query = 'subscriptionsByClusterId'; + logger.debug({req_id, user: whoIs(me), cluster_id, deprecated}, `${query} enter`); await validClusterAuth(me, query, context); const org = await models.User.getOrg(models, me); @@ -79,14 +84,14 @@ const subscriptionResolvers = { // subscription groups: ['dev', 'prod'] , clusterGroupNames: ['stage'] ==> false const foundSubscriptions = await models.Subscription.find({ 'org_id': org_id, groups: { $in: clusterGroupNames }}).lean(); if(foundSubscriptions && foundSubscriptions.length > 0 ) { - urls = await getSubscriptionUrls(org_id, foundSubscriptions); + urls = await getSubscriptionUrls(org_id, foundSubscriptions, deprecated); } } catch (error) { logger.error(error, `There was an error getting ${query} from mongo`); } return urls; }, - subscriptions: async(parent, { org_id }, context) => { + subscriptions: async(parent, { orgId: org_id }, context) => { const { models, me, req_id, logger } = context; const queryName = 'subscriptions'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -95,7 +100,7 @@ const subscriptionResolvers = { const conditions = await getGroupConditions(me, org_id, ACTIONS.READ, 'name', queryName, context); logger.debug({req_id, user: whoIs(me), org_id, conditions }, `${queryName} group conditions are...`); try{ - var subscriptions = await models.Subscription.find({ org_id, ...conditions }, {}, { lean: 1 }); + var subscriptions = await models.Subscription.find({ org_id, ...conditions }, {}).lean({ virtuals: true }); }catch(err){ logger.error(err); throw err; @@ -110,14 +115,14 @@ const subscriptionResolvers = { return subscriptions; }, - subscription: async(parent, { org_id, uuid }, context) => { + subscription: async(parent, { orgId: org_id, uuid }, context) => { const { models, me, req_id, logger } = context; const queryName = 'subscription'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); // await validAuth(me, org_id, ACTIONS.READ, TYPES.SUBSCRIPTION, queryName, context); try{ - var subscriptions = await subscriptionResolvers.Query.subscriptions(parent, { org_id }, { models, me, req_id, logger }); + var subscriptions = await subscriptionResolvers.Query.subscriptions(parent, { orgId: org_id }, { models, me, req_id, logger }); var subscription = subscriptions.find((sub)=>{ return (sub.uuid == uuid); }); @@ -129,7 +134,7 @@ const subscriptionResolvers = { }, }, Mutation: { - addSubscription: async (parent, { org_id, name, groups, channel_uuid, version_uuid }, context)=>{ + addSubscription: async (parent, { orgId: org_id, name, groups, channelUuid: channel_uuid, versionUuid: version_uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'addSubscription'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -172,7 +177,7 @@ const subscriptionResolvers = { throw err; } }, - editSubscription: async (parent, { org_id, uuid, name, groups, channel_uuid, version_uuid }, context)=>{ + editSubscription: async (parent, { orgId: org_id, uuid, name, groups, channelUuid: channel_uuid, versionUuid: version_uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'editSubscription'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -219,7 +224,7 @@ const subscriptionResolvers = { throw err; } }, - setSubscription: async (parent, { org_id, uuid, version_uuid }, context)=>{ + setSubscription: async (parent, { orgId: org_id, uuid, versionUuid: version_uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'setSubscription'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -272,7 +277,7 @@ const subscriptionResolvers = { } }, - removeSubscription: async (parent, { org_id, uuid }, context)=>{ + removeSubscription: async (parent, { orgId: org_id, uuid }, context)=>{ const { models, me, req_id, logger } = context; const queryName = 'removeSubscription'; logger.debug({req_id, user: whoIs(me), org_id }, `${queryName} enter`); @@ -307,7 +312,7 @@ const subscriptionResolvers = { // Sends a message back to a subscribed client // 'parent' is the object representing the subscription that was updated // - return { 'has_updates': true }; + return { has_updates: true, hasUpdates: true }; }, subscribe: withFilter( @@ -343,7 +348,7 @@ const subscriptionResolvers = { const { logger } = context; let found = true; - logger.info('Verify client is authenticated and org_id matches the updated subscription org_id'); + logger.info('Verify client is authenticated and orgId matches the updated subscription orgId'); const { subscriptionUpdated } = parent; const orgKey = context.apiKey || ''; @@ -358,8 +363,9 @@ const subscriptionResolvers = { return Boolean(false); } - if(subscriptionUpdated.data.org_id !== orgId) { - logger.error('wrong org id for this subscription. returning false'); + const orgIdInUpdated = subscriptionUpdated.data.org_id || subscriptionUpdated.data.orgId; + if(orgIdInUpdated !== orgId) { + logger.error('wrong org id for this subscription. returning false'); found = false; } diff --git a/app/apollo/schema/channel.js b/app/apollo/schema/channel.js index 39d939379..73361ea2d 100644 --- a/app/apollo/schema/channel.js +++ b/app/apollo/schema/channel.js @@ -27,7 +27,7 @@ const channelSchema = gql` } type Channel { uuid: String! - org_id: String! + orgId: String! name: String! created: Date! versions: [ChannelVersion] @@ -41,7 +41,7 @@ const channelSchema = gql` success: Boolean } type AddChannelVersionReply { - version_uuid: String! + versionUuid: String! success: Boolean! } type RemoveChannelReply { @@ -53,10 +53,10 @@ const channelSchema = gql` success: Boolean } type DeployableVersion { - org_id: String! + orgId: String! uuid: String! - channel_id: String! - channel_name: String! + channelId: String! + channelName: String! name: String! type: String! description: String @@ -66,46 +66,46 @@ const channelSchema = gql` extend type Query { """ - Gets all channels for org_id + Gets all channels for orgId """ - channels(org_id: String!): [Channel] + channels(orgId: String!): [Channel] """ - Gets a channel from the given org_id and uuid + Gets a channel from the given orgId and uuid """ - channel(org_id: String!, uuid: String! ): Channel + channel(orgId: String!, uuid: String! ): Channel """ Gets a yaml version from this channel """ - getChannelVersion(org_id: String!, channel_uuid: String!, version_uuid: String!): DeployableVersion! + getChannelVersion(orgId: String!, channelUuid: String!, versionUuid: String!): DeployableVersion! } extend type Mutation { """ Adds a channel """ - addChannel(org_id: String!, name: String!): AddChannelReply! + addChannel(orgId: String!, name: String!): AddChannelReply! """ Edits a channel """ - editChannel(org_id: String!, uuid: String!, name: String!): EditChannelReply! + editChannel(orgId: String!, uuid: String!, name: String!): EditChannelReply! """ Adds a yaml version to this channel Requires either content:String or file:Upload """ - addChannelVersion(org_id: String!, channel_uuid: String!, name: String!, type: String!, content: String, file: Upload, description: String): AddChannelVersionReply! + addChannelVersion(orgId: String!, channelUuid: String!, name: String!, type: String!, content: String, file: Upload, description: String): AddChannelVersionReply! """ Removes a channel """ - removeChannel(org_id: String!, uuid: String!): RemoveChannelReply! + removeChannel(orgId: String!, uuid: String!): RemoveChannelReply! """ Removes a channel version """ - removeChannelVersion(org_id: String!, uuid: String!): RemoveChannelVersionReply! + removeChannelVersion(orgId: String!, uuid: String!): RemoveChannelVersionReply! } `; diff --git a/app/apollo/schema/cluster.js b/app/apollo/schema/cluster.js index 8ae46c570..d3c80e13d 100644 --- a/app/apollo/schema/cluster.js +++ b/app/apollo/schema/cluster.js @@ -18,7 +18,7 @@ const { gql } = require('apollo-server-express'); const clusterSchema = gql` type Comment { - user_id: String + userId: String content: String created: Date } @@ -29,13 +29,13 @@ const clusterSchema = gql` } type Cluster { - _id: ID! - org_id: String! - cluster_id: String! + id: ID! + orgId: String! + clusterId: String! metadata: JSON comments: [Comment] registration: JSON - reg_state: String + regState: String groups: [ClusterGroup] created: Date updated: Date @@ -48,7 +48,7 @@ const clusterSchema = gql` } type ClusterCountByKubeVersion { - _id: KubeCountVersion + id: KubeCountVersion count: Int } @@ -59,7 +59,7 @@ const clusterSchema = gql` type RegisterClusterResponse { url: String! - org_id: String! + orgId: String! orgKey: String! clusterId: String! regState: String! @@ -68,29 +68,29 @@ const clusterSchema = gql` extend type Query { """ - Return a cluster based on **org_id** and **cluster_id**. + Return a cluster based on **orgId** and **clusterId**. """ - clusterByClusterID(org_id: String!, cluster_id: String!): Cluster! + clusterByClusterId(orgId: String!, clusterId: String!): Cluster! """ - Return clusters based on **org_id**, sorted with newest document first. + Return clusters based on **orgId**, sorted with newest document first. """ - clustersByOrgID( - org_id: String! + clustersByOrgId( + orgId: String! "**limit**: Number of docs to return. default 50, 0 means return all" limit: Int = 50 - "**startingAfter**: For pagination. Specify the **_id** of the document you want results older than." + "**startingAfter**: For pagination. Specify the **id** of the document you want results older than." startingAfter: String ): [Cluster]! """ - Return clusters based on **org_id** and **filter** on **cluster_id**. Sorted with newest document first. + Return clusters based on **orgId** and **filter** on **clusterId**. Sorted with newest document first. """ clusterSearch( - org_id: String! + orgId: String! """ - **filter**: applies to **cluster_id** field. - If no **filter** is provided, this returns clusters based on just **orig_id**. + **filter**: applies to **clusterId** field. + If no **filter** is provided, this returns clusters based on just **origId**. """ filter: String "**limit**: Number of docs to return. default 50, 0 means return all" @@ -98,38 +98,38 @@ const clusterSchema = gql` ): [Cluster]! """ - Return clusters based on **org_id** whose *updated* field has not been updated in the past day. + Return clusters based on **orgId** whose *updated* field has not been updated in the past day. Sorted with newest document first. """ clusterZombies( - org_id: String! + orgId: String! "**limit**: Number of docs to return. default 50, 0 means return all" limit: Int = 50 ): [Cluster] """ - Return counts of different kubernetes versions deployed in **org_id**. Only active + Return counts of different kubernetes versions deployed in **orgId**. Only active clusters are counted (**updated** field updated in last day). """ - clusterCountByKubeVersion(org_id: String!): [ClusterCountByKubeVersion]! + clusterCountByKubeVersion(orgId: String!): [ClusterCountByKubeVersion]! } extend type Mutation { """ Delete a cluster and all resources under the cluster """ - deleteClusterByClusterID(org_id: String!, cluster_id: String!): DeleteClustersResponse! + deleteClusterByClusterId(orgId: String!, clusterId: String!): DeleteClustersResponse! """ Delete all clusters under an organization and all resources under the deleted clusters """ - deleteClusters(org_id: String!): DeleteClustersResponse! + deleteClusters(orgId: String!): DeleteClustersResponse! """ Register a cluster with razee api for an organization. registration.name is required. """ registerCluster ( - org_id: String! + orgId: String! registration: JSON! ): RegisterClusterResponse! } diff --git a/app/apollo/schema/clusterDistributed.js b/app/apollo/schema/clusterDistributed.js index 8efbd537a..19b5c5aa4 100644 --- a/app/apollo/schema/clusterDistributed.js +++ b/app/apollo/schema/clusterDistributed.js @@ -19,27 +19,27 @@ const { gql } = require('apollo-server-express'); const clusterDistributedSchema = gql` extend type Query { """ - Return a cluster based on **org_id** and **cluster_id**. Multiple DBs will be searched if configured. + Return a cluster based on **orgId** and **clusterId**. Multiple DBs will be searched if configured. """ - clusterDistributedByClusterID(org_id: String!, cluster_id: String!): Cluster + clusterDistributedByClusterId(orgId: String!, clusterId: String!): Cluster """ - Return clusters based on **org_id** from multiple DBs if configured. + Return clusters based on **orgId** from multiple DBs if configured. """ - clustersDistributedByOrgID( - org_id: String + clustersDistributedByOrgId( + orgId: String "**limit**: Number of docs to return. default 50, 0 means return all" limit: Int = 50 ): [Cluster]! """ - Return clusters based on **org_id** and **filter** on **cluster_id** from multiple DBs if configured. + Return clusters based on **orgId** and **filter** on **clusterId** from multiple DBs if configured. """ clusterDistributedSearch( - org_id: String! + orgId: String! """ - **filter**: applies to **cluster_id** field. - If no **filter** is provided, this returns clusters based on just **orig_id**. + **filter**: applies to **clusterId** field. + If no **filter** is provided, this returns clusters based on just **orgId**. """ filter: String "**limit**: Number of docs to return. default 50, 0 means return all" @@ -47,21 +47,21 @@ const clusterDistributedSchema = gql` ): [Cluster]! """ - Return clusters based on **org_id** whose *updated* field has not been updated in the past day. + Return clusters based on **orgId** whose *updated* field has not been updated in the past day. Mulitple DBs will be searched if configured. """ clusterDistributedZombies( - org_id: String! + orgId: String! "**limit**: Number of docs to return. default 50, 0 means return all" limit: Int = 50 ): [Cluster] """ - Return counts of different kubernetes versions deployed in **org_id**. Only active + Return counts of different kubernetes versions deployed in **orgId**. Only active clusters are counted (**updated** field updated in last day). Mulitple DBs will be searched if configured. """ clusterDistributedCountByKubeVersion( - org_id: String! + orgId: String! ): [ClusterCountByKubeVersion]! } `; diff --git a/app/apollo/schema/group.js b/app/apollo/schema/group.js index ac897fc43..28abbb899 100644 --- a/app/apollo/schema/group.js +++ b/app/apollo/schema/group.js @@ -4,7 +4,7 @@ const groupSchema = gql` type Group { uuid: String! - org_id: String! + orgId: String! name: String! owner: BasicUser! created: Date! @@ -12,7 +12,7 @@ const groupSchema = gql` type GroupDetail { uuid: String! - org_id: String! + orgId: String! name: String! owner: BasicUser! created: Date! @@ -41,46 +41,46 @@ const groupSchema = gql` extend type Query { """ - list all groups for org_id + list all groups for orgId """ - groups(org_id: String!): [Group] + groups(orgId: String!): [Group] """ - Gets a group detail for org_id and uuid + Gets a group detail for orgId and uuid """ - group(org_id: String! uuid: String!): GroupDetail + group(orgId: String! uuid: String!): GroupDetail """ - Gets a group detail for org_id and name + Gets a group detail for orgId and name """ - groupByName(org_id: String! name: String!): GroupDetail + groupByName(orgId: String! name: String!): GroupDetail } extend type Mutation { """ Adds a group """ - addGroup(org_id: String! name: String!): AddGroupReply! + addGroup(orgId: String! name: String!): AddGroupReply! """ Removes a group """ - removeGroup(org_id: String! uuid: String!): RemoveGroupReply! + removeGroup(orgId: String! uuid: String!): RemoveGroupReply! """ Removes a group by name """ - removeGroupByName(org_id: String! name: String!): RemoveGroupReply! + removeGroupByName(orgId: String! name: String!): RemoveGroupReply! """ group a list of clusters """ - groupClusters(org_id: String! uuid: String! clusters: [String]!): GroupClustersReply! + groupClusters(orgId: String! uuid: String! clusters: [String]!): GroupClustersReply! """ unGroup a list of clusters """ - unGroupClusters(org_id: String! uuid: String! clusters: [String]!): UnGroupClustersReply! + unGroupClusters(orgId: String! uuid: String! clusters: [String]!): UnGroupClustersReply! } `; diff --git a/app/apollo/schema/organization.js b/app/apollo/schema/organization.js index 06698208a..abd8020a7 100644 --- a/app/apollo/schema/organization.js +++ b/app/apollo/schema/organization.js @@ -22,15 +22,15 @@ const organizationSchema = gql` } type Organization { - _id: ID! + id: ID! name: String! } extend type Query { """ - Return the cluster registration Url for a given **org_id**. + Return the cluster registration Url for a given **orgId**. """ - registrationUrl(org_id: String!): URL! + registrationUrl(orgId: String!): URL! """ Return Organizations the current user belongs to. diff --git a/app/apollo/schema/resource.js b/app/apollo/schema/resource.js index f0d874b09..2268070ff 100644 --- a/app/apollo/schema/resource.js +++ b/app/apollo/schema/resource.js @@ -20,14 +20,14 @@ const resourceSchema = gql` scalar JSON type ClusterInfo { - cluster_id: String! + clusterId: String! name: String! } type Resource { - _id: ID! - org_id: String! - cluster_id: String! + id: ID! + orgId: String! + clusterId: String! cluster: ClusterInfo! selfLink: String! hash: String @@ -50,7 +50,7 @@ const resourceSchema = gql` } type ResourceHistObj{ - _id: String! + id: String! updated: Date! } type ResourceHistList{ @@ -58,7 +58,7 @@ const resourceSchema = gql` items: [ResourceHistObj!]! } type ResourceContentObj{ - _id: String! + id: String! content: String! updated: Date! } @@ -67,48 +67,47 @@ const resourceSchema = gql` extend type Query { """ - Return total resource count for given **org_id**. + Return total resource count for given **orgId**. """ - resourcesCount(org_id: String!): Int + resourcesCount(orgId: String!): Int """ - Search resources against **org_id**, **filter** string, and date ranges. + Search resources against **orgId**, **filter** string, and date ranges. """ - resources(org_id: String! filter: String fromDate: Date toDate: Date limit: Int = 500, kinds: [String!], sort: [SortObj!]): ResourcesList! + resources(orgId: String! filter: String fromDate: Date toDate: Date limit: Int = 500, kinds: [String!], sort: [SortObj!]): ResourcesList! """ - Search resources against **org_id**, **cluster_id**, **filter** string, and date ranges. + Search resources against **orgId**, **clusterId**, **filter** string, and date ranges. """ - resourcesByCluster(org_id: String! cluster_id: String! filter: String limit: Int = 500): ResourcesList! + resourcesByCluster(orgId: String! clusterId: String! filter: String limit: Int = 500): ResourcesList! """ - Return the resource by given resource **_id**. + Return the resource by given resource **id**. """ - resource(org_id: String!, _id: String!, histId: String): Resource + resource(orgId: String!, id: String!, histId: String): Resource """ - return the resource by given **org_id**, **cluster_id** and **selfLink** of the resource. + return the resource by given **orgId**, **clusterId** and **selfLink** of the resource. """ - resourceByKeys(org_id: String! cluster_id: String! selfLink: String!): Resource + resourceByKeys(orgId: String! clusterId: String! selfLink: String!): Resource """ - Search resources against **org_id** and **subscription_id**. + Search resources against **orgId** and **subscriptionId**. """ - resourcesBySubscription(org_id: String! subscription_id: String!): ResourcesList! - + resourcesBySubscription(orgId: String! subscriptionId: String!): ResourcesList! """ Gets the yaml history for a resource """ - resourceHistory(org_id: String!, cluster_id: String!, resourceSelfLink: String!, beforeDate: Date, afterDate: Date, limit: Int = 20): ResourceHistList! + resourceHistory(orgId: String!, clusterId: String!, resourceSelfLink: String!, beforeDate: Date, afterDate: Date, limit: Int = 20): ResourceHistList! """ Gets the content for a yaml hist item """ - resourceContent(org_id: String!, cluster_id: String!, resourceSelfLink: String!, histId: String): ResourceContentObj + resourceContent(orgId: String!, clusterId: String!, resourceSelfLink: String!, histId: String): ResourceContentObj } extend type Subscription { - resourceUpdated(org_id: String!, filter: String): ResourceUpdated! + resourceUpdated(orgId: String!, filter: String): ResourceUpdated! } `; diff --git a/app/apollo/schema/resourceDistributed.js b/app/apollo/schema/resourceDistributed.js index da8312052..ab4d4ed8f 100644 --- a/app/apollo/schema/resourceDistributed.js +++ b/app/apollo/schema/resourceDistributed.js @@ -19,29 +19,29 @@ const { gql } = require('apollo-server-express'); const resourceDistributedSchema = gql` extend type Query { """ - Return total resource count for given **org_id** from multiple DBs if configured. + Return total resource count for given **orgId** from multiple DBs if configured. """ - resourcesDistributedCount(org_id: String!): Int + resourcesDistributedCount(orgId: String!): Int """ - Search resources against **org_id**, **filter** string, and date ranges from multiple DBs if configured. + Search resources against **orgId**, **filter** string, and date ranges from multiple DBs if configured. """ - resourcesDistributed (org_id: String! filter: String fromDate: Date toDate: Date limit: Int = 50): [Resource!] + resourcesDistributed (orgId: String! filter: String fromDate: Date toDate: Date limit: Int = 50): [Resource!] """ - Search resources against **org_id**, **cluster_id**, **filter** string, and date ranges from multiple DBs if configured. + Search resources against **orgId**, **clusterId**, **filter** string, and date ranges from multiple DBs if configured. """ - resourcesDistributedByCluster(org_id: String! cluster_id: String! filter: String limit: Int = 50): [Resource!] + resourcesDistributedByCluster(orgId: String! clusterId: String! filter: String limit: Int = 50): [Resource!] """ - Return the resource by given resource **_id** from multiple DBs if configured. + Return the resource by given resource **id** from multiple DBs if configured. """ - resourceDistributed (_id: ID!): Resource + resourceDistributed (id: ID!): Resource """ - return the resource by given **org_id**, **cluster_id** and **selfLink** of the resource from multiple DBs if configured. + return the resource by given **orgId**, **clusterId** and **selfLink** of the resource from multiple DBs if configured. """ - resourceDistributedByKeys(org_id: String! cluster_id: String! selfLink: String!): Resource + resourceDistributedByKeys(orgId: String! clusterId: String! selfLink: String!): Resource } `; diff --git a/app/apollo/schema/subscription.js b/app/apollo/schema/subscription.js index 76132b175..37b1cf307 100644 --- a/app/apollo/schema/subscription.js +++ b/app/apollo/schema/subscription.js @@ -18,18 +18,18 @@ const { gql } = require('apollo-server-express'); const subscriptionSchema = gql` type BasicUser { - _id: String! + id: String! name: String! } type ChannelSubscription { uuid: String! - org_id: String! + orgId: String! name: String! groups: [String!] - channel_uuid: String! + channelUuid: String! channel: String! version: String! - version_uuid: String! + versionUuid: String! owner: BasicUser! created: Date! updated: Date! @@ -49,55 +49,64 @@ const subscriptionSchema = gql` type AddChannelSubscriptionReply { uuid: String! } - type UpdatedSubscription { + type UpdatedSubscriptionDeprecated { subscription_name: String!, subscription_channel: String!, subscription_version: String!, subscription_uuid: String!, url: String! } - type ChannelsWithLinks { - channel: ChannelSubscription, - links: UpdatedSubscription + type UpdatedSubscription { + subscriptionName: String!, + subscriptionChannel: String!, + subscriptionVersion: String!, + subscriptionUuid: String!, + url: String! } type SubscriptionUpdated { + "**has_updates**: deprecated, use hasUpdates" has_updates: Boolean + hasUpdates: Boolean } extend type Query { """ - Gets all subscriptions for org_id + Gets all subscriptions for orgId """ - subscriptions(org_id: String!): [ChannelSubscription] + subscriptions(orgId: String!): [ChannelSubscription] """ Get a single subscriptions """ - subscription(org_id: String!, uuid: String!): ChannelSubscription + subscription(orgId: String!, uuid: String!): ChannelSubscription + """ + Gets all subscriptions for a cluster, invoked from cluster-subscription agent, deprecated, please use subscriptionsByClusterId + """ + subscriptionsByCluster(cluster_id: String): [UpdatedSubscriptionDeprecated] """ - Gets all subscriptions for a cluster + Gets all subscriptions for a cluster, invoked from cluster-subscription agent """ - subscriptionsByCluster(cluster_id: String): [UpdatedSubscription] + subscriptionsByClusterId(clusterId: String!): [UpdatedSubscription] } extend type Mutation { """ Adds a subscription """ - addSubscription(org_id: String!, name: String!, groups: [String!]!, channel_uuid: String!, version_uuid: String!): AddChannelSubscriptionReply! + addSubscription(orgId: String!, name: String!, groups: [String!]!, channelUuid: String!, versionUuid: String!): AddChannelSubscriptionReply! """ Edits a subscription """ - editSubscription(org_id: String!, uuid: String!, name: String!, groups: [String!]!, channel_uuid: String!, version_uuid: String!): EditChannelSubscriptionReply! + editSubscription(orgId: String!, uuid: String!, name: String!, groups: [String!]!, channelUuid: String!, versionUuid: String!): EditChannelSubscriptionReply! """ Set a configurationVersion """ - setSubscription(org_id: String!, uuid: String!, version_uuid: String! ): SetSubscriptionReply! + setSubscription(orgId: String!, uuid: String!, versionUuid: String! ): SetSubscriptionReply! """ Removes a subscription """ - removeSubscription(org_id: String!, uuid: String!): RemoveChannelSubscriptionReply + removeSubscription(orgId: String!, uuid: String!): RemoveChannelSubscriptionReply } extend type Subscription { subscriptionUpdated: SubscriptionUpdated! diff --git a/app/apollo/schema/user.js b/app/apollo/schema/user.js index e9d5ad79b..a24c954ec 100644 --- a/app/apollo/schema/user.js +++ b/app/apollo/schema/user.js @@ -19,7 +19,7 @@ const { gql } = require('apollo-server-express'); const userSchema = gql` extend type Query { """ - Returns the current user information based on user's bearer token. + Returns the current user information based on user's bearer token.f """ me: User } @@ -32,7 +32,7 @@ const userSchema = gql` username: String! email: String! password: String! - org_name: String + orgName: String role: String ): Token! @@ -47,12 +47,12 @@ const userSchema = gql` } # used by ui to get basic user information after Sign-in - # including id, type of the user, email, default org_id + # including id, type of the user, email, default orgId # and other meta data about this user. type User { id: ID! type: String! - org_id: String! + orgId: String! identifier: String email: String role: String diff --git a/app/apollo/subscription/index.js b/app/apollo/subscription/index.js index e9708fd1b..8d42b51dc 100644 --- a/app/apollo/subscription/index.js +++ b/app/apollo/subscription/index.js @@ -107,7 +107,7 @@ class PubSubImpl { op = 'delete'; } try { - const topic = getStreamingTopic(EVENTS.RESOURCE.UPDATED, resource.org_id); + const topic = getStreamingTopic(EVENTS.RESOURCE.UPDATED, resource.orgId); logger.debug({ op, resource, topic }, 'Publishing resource updates'); await this.pubSub.publish(topic, { resourceUpdated: { resource, op }, diff --git a/app/apollo/test/api.js b/app/apollo/test/api.js index 98c819e6f..b3726ed35 100644 --- a/app/apollo/test/api.js +++ b/app/apollo/test/api.js @@ -22,8 +22,8 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!) { - registrationUrl(org_id: $org_id) { + query($orgId: String!) { + registrationUrl(orgId: $orgId) { url } } @@ -44,7 +44,7 @@ const apiFunc = grahqlUrl => { query: ` query { organizations { - _id + id name } } @@ -66,7 +66,7 @@ const apiFunc = grahqlUrl => { me { id email - org_id + orgId meta } } @@ -82,12 +82,12 @@ const apiFunc = grahqlUrl => { const signUp = async variables => axios.post(grahqlUrl, { query: ` - mutation ($username: String! $email: String! $password: String! $org_name: String $role: String) { + mutation($username: String! $email: String! $password: String! $orgName: String $role: String) { signUp( username: $username email: $email password: $password - org_name: $org_name + orgName: $orgName role: $role ) { token @@ -100,7 +100,7 @@ const apiFunc = grahqlUrl => { const signIn = async variables => axios.post(grahqlUrl, { query: ` - mutation ($login: String! $password: String!) { + mutation($login: String! $password: String!) { signIn( login: $login password: $password @@ -136,11 +136,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!, $_id: String!) { - resource(org_id: $org_id, _id: $_id) { - _id - org_id - cluster_id + query($orgId: String!, $id: String!) { + resource(orgId: $orgId, id: $id) { + id + orgId + clusterId selfLink searchableData created @@ -161,11 +161,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!, $_id: String!, $histId: String) { - resource(org_id: $org_id, _id: $_id, histId: $histId) { - _id - org_id - cluster_id + query($orgId: String!, $id: String!, $histId: String) { + resource(orgId: $orgId, id: $id, histId: $histId) { + id + orgId + clusterId selfLink searchableData created @@ -188,11 +188,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!, $cluster_id: String!, $resourceSelfLink: String!, $beforeDate: Date, $afterDate: Date, $limit: Int = 20) { - resourceHistory(org_id: $org_id, cluster_id: $cluster_id, resourceSelfLink: $resourceSelfLink, beforeDate: $beforeDate, afterDate: $afterDate, limit: $limit) { + query($orgId: String!, $clusterId: String!, $resourceSelfLink: String!, $beforeDate: Date, $afterDate: Date, $limit: Int = 20) { + resourceHistory(orgId: $orgId, clusterId: $clusterId, resourceSelfLink: $resourceSelfLink, beforeDate: $beforeDate, afterDate: $afterDate, limit: $limit) { count, items{ - _id + id updated } } @@ -213,11 +213,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $cluster_id: String! $selfLink: String!){ - resourceByKeys(org_id: $org_id cluster_id: $cluster_id selfLink: $selfLink) { - _id - org_id - cluster_id + query($orgId: String! $clusterId: String! $selfLink: String!){ + resourceByKeys(orgId: $orgId clusterId: $clusterId selfLink: $selfLink) { + id + orgId + clusterId selfLink searchableData created @@ -238,8 +238,8 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!){ - resourcesCount (org_id: $org_id) + query($orgId: String!){ + resourcesCount(orgId: $orgId) } `, variables, @@ -256,13 +256,13 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $filter: String $fromDate: Date $toDate: Date, $kinds: [String!], $sort: [SortObj!]){ - resources (org_id: $org_id filter: $filter fromDate: $fromDate toDate: $toDate, kinds: $kinds, sort: $sort) { + query($orgId: String! $filter: String $fromDate: Date $toDate: Date, $kinds: [String!], $sort: [SortObj!]){ + resources(orgId: $orgId filter: $filter fromDate: $fromDate toDate: $toDate, kinds: $kinds, sort: $sort) { count resources{ - _id - org_id - cluster_id + id + orgId + clusterId selfLink searchableData created @@ -285,13 +285,13 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $cluster_id: String! $filter: String){ - resourcesByCluster (org_id: $org_id cluster_id: $cluster_id filter: $filter) { + query($orgId: String! $clusterId: String! $filter: String){ + resourcesByCluster(orgId: $orgId clusterId: $clusterId filter: $filter) { count resources{ - _id - org_id - cluster_id + id + orgId + clusterId selfLink searchableData created @@ -313,13 +313,13 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $subscription_id: String!){ - resourcesBySubscription(org_id: $org_id subscription_id: $subscription_id ) { + query($orgId: String! $subscriptionId: String!){ + resourcesBySubscription(orgId: $orgId subscriptionId: $subscriptionId ) { count resources{ - _id - org_id - cluster_id + id + orgId + clusterId selfLink searchableData created @@ -341,11 +341,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($_id: ID!) { - resourceDistributed(_id: $_id) { - _id - org_id - cluster_id + query($id: ID!) { + resourceDistributed(id: $id) { + id + orgId + clusterId selfLink searchableData created @@ -366,11 +366,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $cluster_id: String! $selfLink: String!){ - resourceDistributedByKeys(org_id: $org_id cluster_id: $cluster_id selfLink: $selfLink) { - _id - org_id - cluster_id + query($orgId: String! $clusterId: String! $selfLink: String!){ + resourceDistributedByKeys(orgId: $orgId clusterId: $clusterId selfLink: $selfLink) { + id + orgId + clusterId selfLink searchableData created @@ -391,8 +391,8 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String!){ - resourcesDistributedCount (org_id: $org_id) + query($orgId: String!){ + resourcesDistributedCount(orgId: $orgId) } `, variables, @@ -409,11 +409,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $filter: String $fromDate: Date $toDate: Date){ - resourcesDistributed (org_id: $org_id filter: $filter fromDate: $fromDate toDate: $toDate) { - _id - org_id - cluster_id + query($orgId: String! $filter: String $fromDate: Date $toDate: Date){ + resourcesDistributed(orgId: $orgId filter: $filter fromDate: $fromDate toDate: $toDate) { + id + orgId + clusterId selfLink searchableData created @@ -434,11 +434,11 @@ const apiFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $cluster_id: String! $filter: String){ - resourcesDistributedByCluster (org_id: $org_id cluster_id: $cluster_id filter: $filter) { - _id - org_id - cluster_id + query($orgId: String! $clusterId: String! $filter: String){ + resourcesDistributedByCluster(orgId: $orgId clusterId: $clusterId filter: $filter) { + id + orgId + clusterId selfLink searchableData created @@ -457,11 +457,11 @@ const apiFunc = grahqlUrl => { const resourceChanged = async variables => axios.post(grahqlUrl, { query: ` - mutation ($r: JSON!) { + mutation($r: JSON!) { resourceChanged(resource: $r) { - _id - org_id - cluster_id + id + orgId + clusterId selfLink searchableData created diff --git a/app/apollo/test/channel.spec.js b/app/apollo/test/channel.spec.js index 6baf64215..03d912de3 100644 --- a/app/apollo/test/channel.spec.js +++ b/app/apollo/test/channel.spec.js @@ -170,9 +170,9 @@ describe('channel graphql test suite', () => { await createChannels(); // Can be uncommented if you want to see the test data that was added to the DB - // await getPresetOrgs(); - // await getPresetUsers(); - // await getPresetClusters(); + //await getPresetOrgs(); + //await getPresetUsers(); + //await getPresetClusters(); token = await signInUser(models, resourceApi, user01Data); adminToken = await signInUser(models, resourceApi, userRootData); @@ -190,7 +190,7 @@ describe('channel graphql test suite', () => { data: { channels }, }, } = await channelApi.channels(token, { - org_id: org01._id, + orgId: org01._id, uuid: channel_01_uuid, }); @@ -212,7 +212,7 @@ describe('channel graphql test suite', () => { data: { channel }, }, } = await channelApi.channel(token, { - org_id: org01._id, + orgId: org01._id, uuid: channel_01_uuid, }); @@ -234,7 +234,7 @@ describe('channel graphql test suite', () => { data: { addChannel }, }, } = await channelApi.addChannel(adminToken, { - org_id: org01._id, + orgId: org01._id, name: 'a_random_name', }); @@ -257,8 +257,8 @@ describe('channel graphql test suite', () => { data: { addChannelVersion }, }, } = await channelApi.addChannelVersion(adminToken, { - org_id: org01._id, - channel_uuid: channel_01_uuid, + orgId: org01._id, + channelUuid: channel_01_uuid, name: `${channel_01_name}:v.0.1`, type: 'json', content: '{"n0": 123.45}', @@ -266,7 +266,7 @@ describe('channel graphql test suite', () => { }); expect(addChannelVersion.success).to.equal(true); - expect(addChannelVersion.version_uuid).to.be.an('string'); + expect(addChannelVersion.versionUuid).to.be.an('string'); // step 2: add another channel version by admin token const { @@ -274,8 +274,8 @@ describe('channel graphql test suite', () => { data: { addChannelVersion : addChannelVersion2 }, }, } = await channelApi.addChannelVersion(adminToken, { - org_id: org01._id, - channel_uuid: channel_01_uuid, + orgId: org01._id, + channelUuid: channel_01_uuid, name: `${channel_01_name}:v.0.2`, type: 'json', content: '{"n0": 456.78}', @@ -283,7 +283,7 @@ describe('channel graphql test suite', () => { }); expect(addChannelVersion2.success).to.equal(true); - expect(addChannelVersion2.version_uuid).to.be.an('string'); + expect(addChannelVersion2.versionUuid).to.be.an('string'); // step 3: get a channel version by user1 token const { @@ -291,12 +291,12 @@ describe('channel graphql test suite', () => { data: { getChannelVersion }, }, } = await channelApi.getChannelVersion(token, { - org_id: org01._id, - channel_uuid: channel_01_uuid, - version_uuid: addChannelVersion.version_uuid, + orgId: org01._id, + channelUuid: channel_01_uuid, + versionUuid: addChannelVersion.versionUuid, }); - expect(getChannelVersion.channel_name).to.equal(channel_01_name); + expect(getChannelVersion.channelName).to.equal(channel_01_name); expect(getChannelVersion.name).to.equal(`${channel_01_name}:v.0.1`); expect(getChannelVersion.content).to.equal('{"n0": 123.45}'); expect(getChannelVersion.created).to.be.an('string'); @@ -319,7 +319,7 @@ describe('channel graphql test suite', () => { data: { editChannel }, }, } = await channelApi.editChannel(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: channel_02_uuid, name: `${channel_02_name}_new` }); @@ -333,33 +333,31 @@ describe('channel graphql test suite', () => { data }, } = await channelApi.editChannel(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: 'not_exit_uuid', name: `${channel_02_name}_new` }); expect(data).to.equal(null); - // step 2 remove the channel const { data: { data: { removeChannel }, }, } = await channelApi.removeChannel(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: channel_02_uuid, }); expect(removeChannel.success).to.equal(true); expect(removeChannel.uuid).to.equal(channel_02_uuid); - // step 3 validate the channel 02 is not there const { data: { data: { channel }, }, } = await channelApi.channel(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: channel_02_uuid, }); @@ -382,15 +380,15 @@ describe('channel graphql test suite', () => { data: { addChannelVersion }, }, } = await channelApi.addChannelVersion(adminToken, { - org_id: org01._id, - channel_uuid: channel_01_uuid, + orgId: org01._id, + channelUuid: channel_01_uuid, name: `${channel_01_name}:v.0.4`, type: 'json', content: '{"n0": 123.45}', description: `${channel_01_name}:v.0.4` }); expect(addChannelVersion.success).to.equal(true); - expect(addChannelVersion.version_uuid).to.be.an('string'); + expect(addChannelVersion.versionUuid).to.be.an('string'); // step 2: remove the channel version by an adminToken // console.log('here step 2 in remove channel version'); const { @@ -398,9 +396,9 @@ describe('channel graphql test suite', () => { data: { getChannelVersion }, }, } = await channelApi.getChannelVersion(token, { - org_id: org01._id, - channel_uuid: channel_01_uuid, - version_uuid: addChannelVersion.version_uuid, + orgId: org01._id, + channelUuid: channel_01_uuid, + versionUuid: addChannelVersion.versionUuid, }); expect(getChannelVersion.name).to.equal(`${channel_01_name}:v.0.4`); expect(getChannelVersion.content).to.equal('{"n0": 123.45}'); @@ -410,7 +408,7 @@ describe('channel graphql test suite', () => { data: { removeChannelVersion }, }, } = await channelApi.removeChannelVersion(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: getChannelVersion.uuid, }); expect(removeChannelVersion.success).to.equal(true); @@ -422,7 +420,7 @@ describe('channel graphql test suite', () => { data: { channel }, }, } = await channelApi.channel(token, { - org_id: org01._id, + orgId: org01._id, uuid: channel_01_uuid, }); console.log(`channel read = ${JSON.stringify(channel.versions)}`); diff --git a/app/apollo/test/channelApi.js b/app/apollo/test/channelApi.js index 57bcdb3ef..990922964 100644 --- a/app/apollo/test/channelApi.js +++ b/app/apollo/test/channelApi.js @@ -22,10 +22,10 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!) { - channels( org_id: $org_id) { + query($orgId: String!) { + channels(orgId: $orgId) { uuid - org_id + orgId name created versions { @@ -51,10 +51,10 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $uuid: String! ) { - channel( org_id: $org_id uuid: $uuid ) { + query($orgId: String! $uuid: String!) { + channel(orgId: $orgId uuid: $uuid) { uuid - org_id + orgId name created versions { @@ -80,12 +80,12 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $channel_uuid: String!, $version_uuid: String! ) { - getChannelVersion( org_id: $org_id channel_uuid: $channel_uuid version_uuid: $version_uuid) { - org_id + query($orgId: String! $channelUuid: String!, $versionUuid: String!) { + getChannelVersion(orgId: $orgId channelUuid: $channelUuid versionUuid: $versionUuid) { + orgId uuid - channel_id - channel_name + channelId + channelName name type description @@ -108,9 +108,9 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $channel_uuid: String!, $name: String!, $type: String!, $content: String!, $description: String) { - addChannelVersion( org_id: $org_id channel_uuid: $channel_uuid name: $name type: $type content: $content description: $description ) { - version_uuid + mutation($orgId: String!, $channelUuid: String!, $name: String!, $type: String!, $content: String!, $description: String) { + addChannelVersion(orgId: $orgId channelUuid: $channelUuid name: $name type: $type content: $content description: $description) { + versionUuid success } } @@ -129,8 +129,8 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!) { - removeChannelVersion( org_id: $org_id uuid: $uuid) { + mutation($orgId: String!, $uuid: String!) { + removeChannelVersion(orgId: $orgId uuid: $uuid) { uuid success } @@ -150,8 +150,8 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!,$name: String!) { - addChannel( org_id: $org_id name: $name) { + mutation($orgId: String!,$name: String!) { + addChannel(orgId: $orgId name: $name) { uuid } } @@ -170,8 +170,8 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!, $name: String!) { - editChannel( org_id: $org_id uuid: $uuid name: $name) { + mutation($orgId: String!, $uuid: String!, $name: String!) { + editChannel(orgId: $orgId uuid: $uuid name: $name) { uuid success name @@ -192,8 +192,8 @@ const channelFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!) { - removeChannel( org_id: $org_id uuid: $uuid) { + mutation($orgId: String!, $uuid: String!) { + removeChannel(orgId: $orgId uuid: $uuid) { uuid success } diff --git a/app/apollo/test/cluster.spec.js b/app/apollo/test/cluster.spec.js index 9e12d0339..413de3b9b 100644 --- a/app/apollo/test/cluster.spec.js +++ b/app/apollo/test/cluster.spec.js @@ -232,9 +232,9 @@ describe('cluster graphql test suite', () => { await createClusters(); // Can be uncommented if you want to see the test data that was added to the DB - // await getPresetOrgs(); - // await getPresetUsers(); - // await getPresetClusters(); + //await getPresetOrgs(); + //await getPresetUsers(); + //await getPresetClusters(); token = await signInUser(models, resourceApi, user01Data); adminToken = await signInUser(models, resourceApi, userRootData); @@ -250,14 +250,14 @@ describe('cluster graphql test suite', () => { const clusterId1 = 'cluster_01'; const { data: { - data: { clusterByClusterID }, + data: { clusterByClusterId }, }, } = await clusterApi.byClusterID(token, { - org_id: org01._id, - cluster_id: clusterId1, + orgId: org01._id, + clusterId: clusterId1, }); - expect(clusterByClusterID.cluster_id).to.equal(clusterId1); + expect(clusterByClusterId.clusterId).to.equal(clusterId1); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -272,14 +272,14 @@ describe('cluster graphql test suite', () => { try { const { data: { - data: { clustersByOrgID }, + data: { clustersByOrgId }, }, } = await clusterApi.byOrgID(token, { - org_id: org01._id, + orgId: org01._id, }); - expect(clustersByOrgID).to.be.an('array'); - expect(clustersByOrgID).to.have.length(4); + expect(clustersByOrgId).to.be.an('array'); + expect(clustersByOrgId).to.have.length(4); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -296,19 +296,19 @@ describe('cluster graphql test suite', () => { try { const { data: { - data: { clustersByOrgID }, + data: { clustersByOrgId }, }, } = await clusterApi.byOrgID(token, { - org_id: org01._id, + orgId: org01._id, limit: 2, }); + + expect(clustersByOrgId).to.be.an('array'); + expect(clustersByOrgId).to.have.length(2); + expect(clustersByOrgId[0].clusterId).to.equal('cluster_04'); + expect(clustersByOrgId[1].clusterId).to.equal('cluster_03'); - expect(clustersByOrgID).to.be.an('array'); - expect(clustersByOrgID).to.have.length(2); - expect(clustersByOrgID[0].cluster_id).to.equal('cluster_04'); - expect(clustersByOrgID[1].cluster_id).to.equal('cluster_03'); - - next = clustersByOrgID[1]._id; + next = clustersByOrgId[1].id; } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -317,22 +317,22 @@ describe('cluster graphql test suite', () => { } throw error; } - + try { const { data: { - data: { clustersByOrgID }, + data: { clustersByOrgId }, }, } = await clusterApi.byOrgID(token, { - org_id: org01._id, + orgId: org01._id, limit: 2, startingAfter: next, }); - expect(clustersByOrgID).to.be.an('array'); - expect(clustersByOrgID).to.have.length(2); - expect(clustersByOrgID[0].cluster_id).to.equal('cluster_02'); - expect(clustersByOrgID[1].cluster_id).to.equal('cluster_01'); + expect(clustersByOrgId).to.be.an('array'); + expect(clustersByOrgId).to.have.length(2); + expect(clustersByOrgId[0].clusterId).to.equal('cluster_02'); + expect(clustersByOrgId[1].clusterId).to.equal('cluster_01'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -350,7 +350,7 @@ describe('cluster graphql test suite', () => { data: { clusterSearch }, }, } = await clusterApi.search(token, { - org_id: org01._id, + orgId: org01._id, filter: 'cluster', limit: 45, }); @@ -374,14 +374,14 @@ describe('cluster graphql test suite', () => { data: { clusterSearch }, }, } = await clusterApi.search(token, { - org_id: org01._id, + orgId: org01._id, filter: 'cluster', limit: 1, }); expect(clusterSearch).to.be.an('array'); expect(clusterSearch).to.have.length(1); - expect(clusterSearch[0].cluster_id).to.equal('cluster_04'); + expect(clusterSearch[0].clusterId).to.equal('cluster_04'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -399,7 +399,7 @@ describe('cluster graphql test suite', () => { data: { clusterSearch }, }, } = await clusterApi.search(token, { - org_id: org01._id, + orgId: org01._id, }); expect(clusterSearch).to.be.an('array'); @@ -421,13 +421,13 @@ describe('cluster graphql test suite', () => { data: { clusterSearch }, }, } = await clusterApi.search(token, { - org_id: org01._id, + orgId: org01._id, limit: 1, }); expect(clusterSearch).to.be.an('array'); expect(clusterSearch).to.have.length(1); - expect(clusterSearch[0].cluster_id).to.equal('cluster_04'); + expect(clusterSearch[0].clusterId).to.equal('cluster_04'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -444,11 +444,11 @@ describe('cluster graphql test suite', () => { data: { data: { clusterCountByKubeVersion }, }, - } = await clusterApi.kubeVersionCount(token, { org_id: org01._id }); + } = await clusterApi.kubeVersionCount(token, { orgId: org01._id }); expect(clusterCountByKubeVersion).to.be.an('array'); expect(clusterCountByKubeVersion).to.have.length(2); - expect(clusterCountByKubeVersion[0]._id.minor).to.equal('16'); - expect(clusterCountByKubeVersion[1]._id.minor).to.equal('17'); + expect(clusterCountByKubeVersion[0].id.minor).to.equal('16'); + expect(clusterCountByKubeVersion[1].id.minor).to.equal('17'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -465,11 +465,11 @@ describe('cluster graphql test suite', () => { data: { data: { clusterZombies }, }, - } = await clusterApi.zombies(token, { org_id: org01._id }); + } = await clusterApi.zombies(token, { orgId: org01._id }); expect(clusterZombies).to.be.an('array'); expect(clusterZombies).to.have.length(1); - expect(clusterZombies[0].cluster_id).to.equal('cluster_04'); + expect(clusterZombies[0].clusterId).to.equal('cluster_04'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -501,9 +501,9 @@ describe('cluster graphql test suite', () => { }, }); - const data = await clusterApi.deleteClusterByClusterID(token, { - org_id: org01._id, - cluster_id: clusterIdToBeDeleted, + const data = await clusterApi.deleteClusterByClusterId(token, { + orgId: org01._id, + clusterId: clusterIdToBeDeleted, }); expect(data.data.data).to.equal(null); expect(data.data.errors[0].message).to.be.a('string'); @@ -517,7 +517,6 @@ describe('cluster graphql test suite', () => { } }); - it('delete cluster by clusterID by an admin user', async () => { try { const clusterIdToBeDeleted = 'cluster_to_be_deleted'; @@ -552,15 +551,15 @@ describe('cluster graphql test suite', () => { const { data: { - data: { deleteClusterByClusterID }, + data: { deleteClusterByClusterId }, }, - } = await clusterApi.deleteClusterByClusterID(adminToken, { - org_id: org01._id, - cluster_id: clusterIdToBeDeleted, + } = await clusterApi.deleteClusterByClusterId(adminToken, { + orgId: org01._id, + clusterId: clusterIdToBeDeleted, }); - expect(deleteClusterByClusterID.deletedClusterCount).to.equal(1); - expect(deleteClusterByClusterID.deletedClusterCount).to.equal(1); + expect(deleteClusterByClusterId.deletedClusterCount).to.equal(1); + expect(deleteClusterByClusterId.deletedClusterCount).to.equal(1); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -571,7 +570,6 @@ describe('cluster graphql test suite', () => { } }); - it('delete clusters by an admin user', async () => { try { const clusterIdToBeDeleted = 'cluster_to_be_deleted'; @@ -609,8 +607,8 @@ describe('cluster graphql test suite', () => { data: { deleteClusters }, }, } = await clusterApi.deleteClusters(adminToken, { - org_id: org01._id, - cluster_id: clusterIdToBeDeleted, + orgId: org01._id, + clusterId: clusterIdToBeDeleted, }); expect(deleteClusters.deletedClusterCount).to.be.above(0); @@ -632,7 +630,7 @@ describe('cluster graphql test suite', () => { data: { registerCluster }, }, } = await clusterApi.registerCluster(adminToken, { - org_id: org01._id, + orgId: org01._id, registration: { name: 'my-cluster' }, }); expect(registerCluster.url).to.be.an('string'); diff --git a/app/apollo/test/clusterApi.js b/app/apollo/test/clusterApi.js index d804dafe1..2ca2f60e1 100644 --- a/app/apollo/test/clusterApi.js +++ b/app/apollo/test/clusterApi.js @@ -22,11 +22,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $cluster_id: String!) { - clusterByClusterID( org_id: $org_id cluster_id: $cluster_id) { - _id - org_id - cluster_id + query($orgId: String! $clusterId: String!) { + clusterByClusterId(orgId: $orgId clusterId: $clusterId) { + id + orgId + clusterId } } `, @@ -44,11 +44,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $cluster_id: String!) { - clusterDistributedByClusterID( org_id: $org_id cluster_id: $cluster_id) { - _id - org_id - cluster_id + query($orgId: String! $clusterId: String!) { + clusterDistributedByClusterId(orgId: $orgId clusterId: $clusterId) { + id + orgId + clusterId } } `, @@ -66,11 +66,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String! $limit: Int, $startingAfter: String) { - clustersByOrgID ( org_id: $org_id limit: $limit startingAfter: $startingAfter) { - _id - org_id - cluster_id + query($orgId: String! $limit: Int, $startingAfter: String) { + clustersByOrgId(orgId: $orgId limit: $limit startingAfter: $startingAfter) { + id + orgId + clusterId } } `, @@ -88,11 +88,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query ($org_id: String $limit: Int) { - clustersDistributedByOrgID ( org_id: $org_id limit: $limit) { - _id - org_id - cluster_id + query($orgId: String $limit: Int) { + clustersDistributedByOrgId(orgId: $orgId limit: $limit) { + id + orgId + clusterId } } `, @@ -110,11 +110,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $filter: String $limit: Int) { - clusterSearch( org_id: $org_id filter: $filter limit: $limit) { - _id - org_id - cluster_id + query($orgId: String! $filter: String $limit: Int) { + clusterSearch(orgId: $orgId filter: $filter limit: $limit) { + id + orgId + clusterId } } `, @@ -132,11 +132,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $filter: String $limit: Int) { - clusterDistributedSearch( org_id: $org_id filter: $filter limit: $limit) { - _id - org_id - cluster_id + query($orgId: String! $filter: String $limit: Int) { + clusterDistributedSearch(orgId: $orgId filter: $filter limit: $limit) { + id + orgId + clusterId } } `, @@ -154,9 +154,9 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!) { - clusterCountByKubeVersion( org_id: $org_id) { - _id { + query($orgId: String!) { + clusterCountByKubeVersion(orgId: $orgId) { + id { major minor } @@ -178,9 +178,9 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!) { - clusterDistributedCountByKubeVersion( org_id: $org_id) { - _id { + query($orgId: String!) { + clusterDistributedCountByKubeVersion(orgId: $orgId) { + id { major minor } @@ -202,11 +202,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $limit: Int) { - clusterZombies( org_id: $org_id limit: $limit) { - _id - org_id - cluster_id + query($orgId: String! $limit: Int) { + clusterZombies(orgId: $orgId limit: $limit) { + id + orgId + clusterId updated } } @@ -225,11 +225,11 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String! $limit: Int) { - clusterDistributedZombies( org_id: $org_id limit: $limit) { - _id - org_id - cluster_id + query($orgId: String! $limit: Int) { + clusterDistributedZombies(orgId: $orgId limit: $limit) { + id + orgId + clusterId updated } } @@ -243,13 +243,13 @@ const clusterFunc = grahqlUrl => { }, ); - const deleteClusterByClusterID = async (token, variables) => + const deleteClusterByClusterId = async (token, variables) => axios.post( grahqlUrl, { query: ` - mutation($org_id: String! $cluster_id: String!) { - deleteClusterByClusterID( org_id: $org_id cluster_id: $cluster_id) { + mutation($orgId: String! $clusterId: String!) { + deleteClusterByClusterId(orgId: $orgId clusterId: $clusterId) { deletedClusterCount deletedResourceCount } @@ -269,8 +269,8 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!) { - deleteClusters( org_id: $org_id ) { + mutation($orgId: String!) { + deleteClusters(orgId: $orgId) { deletedClusterCount deletedResourceCount } @@ -289,8 +289,8 @@ const clusterFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!,$registration: JSON!) { - registerCluster( org_id: $org_id registration: $registration) { + mutation($orgId: String!,$registration: JSON!) { + registerCluster(orgId: $orgId registration: $registration) { url } } @@ -315,7 +315,7 @@ const clusterFunc = grahqlUrl => { kubeVersionCountDistributed, zombies, zombiesDistributed, - deleteClusterByClusterID, + deleteClusterByClusterId, deleteClusters, registerCluster, }; diff --git a/app/apollo/test/clusterDistributed.spec.js b/app/apollo/test/clusterDistributed.spec.js index b716a7a6a..e5038d169 100644 --- a/app/apollo/test/clusterDistributed.spec.js +++ b/app/apollo/test/clusterDistributed.spec.js @@ -246,17 +246,16 @@ describe('clusterDistrubuted graphql test suite', () => { it('get cluster by clusterID from distributed DBs', async () => { try { const clusterId1 = 'cluster_01'; - const { data: { - data: { clusterDistributedByClusterID }, + data: { clusterDistributedByClusterId }, }, } = await clusterApi.byClusterIDDistributed(token, { - org_id: org01._id, - cluster_id: clusterId1, + orgId: org01._id, + clusterId: clusterId1, }); - expect(clusterDistributedByClusterID.cluster_id).to.equal(clusterId1); + expect(clusterDistributedByClusterId.clusterId).to.equal(clusterId1); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -271,14 +270,14 @@ describe('clusterDistrubuted graphql test suite', () => { try { const { data: { - data: { clustersDistributedByOrgID }, + data: { clustersDistributedByOrgId }, }, } = await clusterApi.byOrgIDDistributed(token, { - org_id: org01._id, + orgId: org01._id, }); - expect(clustersDistributedByOrgID).to.be.an('array'); - expect(clustersDistributedByOrgID).to.have.length(4); + expect(clustersDistributedByOrgId).to.be.an('array'); + expect(clustersDistributedByOrgId).to.have.length(4); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -296,7 +295,7 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedSearch }, }, } = await clusterApi.searchDistributed(token, { - org_id: org01._id, + orgId: org01._id, filter: 'cluster', limit: 50, }); @@ -320,14 +319,14 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedSearch }, }, } = await clusterApi.searchDistributed(token, { - org_id: org01._id, + orgId: org01._id, filter: 'cluster', limit: 1, }); expect(clusterDistributedSearch).to.be.an('array'); expect(clusterDistributedSearch).to.have.length(2); - expect(clusterDistributedSearch[0].cluster_id).to.equal('cluster_03'); + expect(clusterDistributedSearch[0].clusterId).to.equal('cluster_03'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -345,7 +344,7 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedSearch }, }, } = await clusterApi.searchDistributed(token, { - org_id: org01._id, + orgId: org01._id, }); expect(clusterDistributedSearch).to.be.an('array'); @@ -367,13 +366,13 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedSearch }, }, } = await clusterApi.searchDistributed(token, { - org_id: org01._id, + orgId: org01._id, limit: 1, }); expect(clusterDistributedSearch).to.be.an('array'); expect(clusterDistributedSearch).to.have.length(2); - expect(clusterDistributedSearch[0].cluster_id).to.equal('cluster_03'); + expect(clusterDistributedSearch[0].clusterId).to.equal('cluster_03'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -393,13 +392,12 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedCountByKubeVersion }, }, } = await clusterApi.kubeVersionCountDistributed(token, { - org_id: org01._id, + orgId: org01._id, }); - expect(clusterDistributedCountByKubeVersion).to.be.an('array'); expect(clusterDistributedCountByKubeVersion).to.have.length(2); - expect(clusterDistributedCountByKubeVersion[0]._id.minor).to.equal('16'); - expect(clusterDistributedCountByKubeVersion[1]._id.minor).to.equal('17'); + expect(clusterDistributedCountByKubeVersion[0].id.minor).to.equal('16'); + expect(clusterDistributedCountByKubeVersion[1].id.minor).to.equal('17'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -409,7 +407,7 @@ describe('clusterDistrubuted graphql test suite', () => { throw error; } }); - + it('get all zombie clusters who have not been updated in last day from distributed DBs', async () => { try { const { @@ -417,12 +415,12 @@ describe('clusterDistrubuted graphql test suite', () => { data: { clusterDistributedZombies }, }, } = await clusterApi.zombiesDistributed(token, { - org_id: org01._id, + orgId: org01._id, }); expect(clusterDistributedZombies).to.be.an('array'); expect(clusterDistributedZombies).to.have.length(1); - expect(clusterDistributedZombies[0].cluster_id).to.equal('cluster_04'); + expect(clusterDistributedZombies[0].clusterId).to.equal('cluster_04'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); diff --git a/app/apollo/test/data/local/channel.spec.root.json b/app/apollo/test/data/local/channel.spec.root.json index 05f38fa7d..b3dc9a951 100644 --- a/app/apollo/test/data/local/channel.spec.root.json +++ b/app/apollo/test/data/local/channel.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "root@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/channel.spec.user01.json b/app/apollo/test/data/local/channel.spec.user01.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/local/channel.spec.user01.json +++ b/app/apollo/test/data/local/channel.spec.user01.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/local/channel.spec.user77.json b/app/apollo/test/data/local/channel.spec.user77.json index 1a7454eee..cd4ccd356 100644 --- a/app/apollo/test/data/local/channel.spec.user77.json +++ b/app/apollo/test/data/local/channel.spec.user77.json @@ -2,5 +2,5 @@ "username": "user77", "email": "user77@us.ibm.com", "password": "password123", - "org_name": "org_77" + "orgName": "org_77" } \ No newline at end of file diff --git a/app/apollo/test/data/local/cluster.spec.root.json b/app/apollo/test/data/local/cluster.spec.root.json index 05f38fa7d..b3dc9a951 100644 --- a/app/apollo/test/data/local/cluster.spec.root.json +++ b/app/apollo/test/data/local/cluster.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "root@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/cluster.spec.user01.json b/app/apollo/test/data/local/cluster.spec.user01.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/local/cluster.spec.user01.json +++ b/app/apollo/test/data/local/cluster.spec.user01.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/local/cluster.spec.user77.json b/app/apollo/test/data/local/cluster.spec.user77.json index 1a7454eee..cd4ccd356 100644 --- a/app/apollo/test/data/local/cluster.spec.user77.json +++ b/app/apollo/test/data/local/cluster.spec.user77.json @@ -2,5 +2,5 @@ "username": "user77", "email": "user77@us.ibm.com", "password": "password123", - "org_name": "org_77" + "orgName": "org_77" } \ No newline at end of file diff --git a/app/apollo/test/data/local/organization.spec.root.json b/app/apollo/test/data/local/organization.spec.root.json index e461f837c..80d08d72f 100644 --- a/app/apollo/test/data/local/organization.spec.root.json +++ b/app/apollo/test/data/local/organization.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "admin@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/organization.spec.user01.json b/app/apollo/test/data/local/organization.spec.user01.json index 8f29eed0c..0b7b55ebe 100644 --- a/app/apollo/test/data/local/organization.spec.user01.json +++ b/app/apollo/test/data/local/organization.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "READER" } \ No newline at end of file diff --git a/app/apollo/test/data/local/resource.spec.user01.json b/app/apollo/test/data/local/resource.spec.user01.json index 50bf5ffd6..fbb612704 100644 --- a/app/apollo/test/data/local/resource.spec.user01.json +++ b/app/apollo/test/data/local/resource.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/resource.spec.user02.json b/app/apollo/test/data/local/resource.spec.user02.json index 06c10b046..f8e4b7b82 100644 --- a/app/apollo/test/data/local/resource.spec.user02.json +++ b/app/apollo/test/data/local/resource.spec.user02.json @@ -2,6 +2,6 @@ "username": "user02", "email": "user02@us.ibm.com", "password": "password123", - "org_name": "org_02", + "orgName": "org_02", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/resourceDistributed.spec.user01 copy.json b/app/apollo/test/data/local/resourceDistributed.spec.user01 copy.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/local/resourceDistributed.spec.user01 copy.json +++ b/app/apollo/test/data/local/resourceDistributed.spec.user01 copy.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/local/user.spec.root.json b/app/apollo/test/data/local/user.spec.root.json index e461f837c..80d08d72f 100644 --- a/app/apollo/test/data/local/user.spec.root.json +++ b/app/apollo/test/data/local/user.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "admin@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/local/user.spec.user01.json b/app/apollo/test/data/local/user.spec.user01.json index 8f29eed0c..0b7b55ebe 100644 --- a/app/apollo/test/data/local/user.spec.user01.json +++ b/app/apollo/test/data/local/user.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "READER" } \ No newline at end of file diff --git a/app/apollo/test/data/local/user.spec.user02.json b/app/apollo/test/data/local/user.spec.user02.json index 1e443bbf7..94e130359 100644 --- a/app/apollo/test/data/local/user.spec.user02.json +++ b/app/apollo/test/data/local/user.spec.user02.json @@ -2,6 +2,6 @@ "username": "user02", "email": "user02@us.ibm.com", "password": "passwordabc", - "org_name": "org_77", + "orgName": "org_77", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/channel.spec.root.json b/app/apollo/test/data/passport.local/channel.spec.root.json index 05f38fa7d..b3dc9a951 100644 --- a/app/apollo/test/data/passport.local/channel.spec.root.json +++ b/app/apollo/test/data/passport.local/channel.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "root@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/channel.spec.user01.json b/app/apollo/test/data/passport.local/channel.spec.user01.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/passport.local/channel.spec.user01.json +++ b/app/apollo/test/data/passport.local/channel.spec.user01.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/channel.spec.user77.json b/app/apollo/test/data/passport.local/channel.spec.user77.json index 1a7454eee..cd4ccd356 100644 --- a/app/apollo/test/data/passport.local/channel.spec.user77.json +++ b/app/apollo/test/data/passport.local/channel.spec.user77.json @@ -2,5 +2,5 @@ "username": "user77", "email": "user77@us.ibm.com", "password": "password123", - "org_name": "org_77" + "orgName": "org_77" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/cluster.spec.root.json b/app/apollo/test/data/passport.local/cluster.spec.root.json index 8bf69c479..e3ed438d4 100644 --- a/app/apollo/test/data/passport.local/cluster.spec.root.json +++ b/app/apollo/test/data/passport.local/cluster.spec.root.json @@ -3,6 +3,6 @@ "username": "root", "email": "root@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/cluster.spec.user01.json b/app/apollo/test/data/passport.local/cluster.spec.user01.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/passport.local/cluster.spec.user01.json +++ b/app/apollo/test/data/passport.local/cluster.spec.user01.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/cluster.spec.user77.json b/app/apollo/test/data/passport.local/cluster.spec.user77.json index 1a7454eee..cd4ccd356 100644 --- a/app/apollo/test/data/passport.local/cluster.spec.user77.json +++ b/app/apollo/test/data/passport.local/cluster.spec.user77.json @@ -2,5 +2,5 @@ "username": "user77", "email": "user77@us.ibm.com", "password": "password123", - "org_name": "org_77" + "orgName": "org_77" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/organization.spec.root.json b/app/apollo/test/data/passport.local/organization.spec.root.json index e461f837c..80d08d72f 100644 --- a/app/apollo/test/data/passport.local/organization.spec.root.json +++ b/app/apollo/test/data/passport.local/organization.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "admin@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/organization.spec.user01.json b/app/apollo/test/data/passport.local/organization.spec.user01.json index 8f29eed0c..0b7b55ebe 100644 --- a/app/apollo/test/data/passport.local/organization.spec.user01.json +++ b/app/apollo/test/data/passport.local/organization.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "READER" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/resource.spec.user01.json b/app/apollo/test/data/passport.local/resource.spec.user01.json index 50bf5ffd6..fbb612704 100644 --- a/app/apollo/test/data/passport.local/resource.spec.user01.json +++ b/app/apollo/test/data/passport.local/resource.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/resource.spec.user02.json b/app/apollo/test/data/passport.local/resource.spec.user02.json index 06c10b046..f8e4b7b82 100644 --- a/app/apollo/test/data/passport.local/resource.spec.user02.json +++ b/app/apollo/test/data/passport.local/resource.spec.user02.json @@ -2,6 +2,6 @@ "username": "user02", "email": "user02@us.ibm.com", "password": "password123", - "org_name": "org_02", + "orgName": "org_02", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/resourceDistributed.spec.user01 copy.json b/app/apollo/test/data/passport.local/resourceDistributed.spec.user01 copy.json index 1b12779a4..f9e9619ca 100644 --- a/app/apollo/test/data/passport.local/resourceDistributed.spec.user01 copy.json +++ b/app/apollo/test/data/passport.local/resourceDistributed.spec.user01 copy.json @@ -2,5 +2,5 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01" + "orgName": "org_01" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/user.spec.root.json b/app/apollo/test/data/passport.local/user.spec.root.json index e461f837c..80d08d72f 100644 --- a/app/apollo/test/data/passport.local/user.spec.root.json +++ b/app/apollo/test/data/passport.local/user.spec.root.json @@ -2,6 +2,6 @@ "username": "root", "email": "admin@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/user.spec.user01.json b/app/apollo/test/data/passport.local/user.spec.user01.json index 8f29eed0c..0b7b55ebe 100644 --- a/app/apollo/test/data/passport.local/user.spec.user01.json +++ b/app/apollo/test/data/passport.local/user.spec.user01.json @@ -2,6 +2,6 @@ "username": "user01", "email": "user01@us.ibm.com", "password": "password123", - "org_name": "org_01", + "orgName": "org_01", "role": "READER" } \ No newline at end of file diff --git a/app/apollo/test/data/passport.local/user.spec.user02.json b/app/apollo/test/data/passport.local/user.spec.user02.json index 1e443bbf7..94e130359 100644 --- a/app/apollo/test/data/passport.local/user.spec.user02.json +++ b/app/apollo/test/data/passport.local/user.spec.user02.json @@ -2,6 +2,6 @@ "username": "user02", "email": "user02@us.ibm.com", "password": "passwordabc", - "org_name": "org_77", + "orgName": "org_77", "role": "ADMIN" } \ No newline at end of file diff --git a/app/apollo/test/group.spec.js b/app/apollo/test/group.spec.js index 0c4ad65f0..3dfa0a116 100644 --- a/app/apollo/test/group.spec.js +++ b/app/apollo/test/group.spec.js @@ -431,7 +431,7 @@ describe('groups graphql test suite', () => { data: { groups }, }, } = await groupApi.groups(token, { - org_id: org01._id, + orgId: org01._id, }); console.log(`get all groups by Org ID: groups = ${JSON.stringify(groups)}`); expect(groups).to.be.an('array'); @@ -453,7 +453,7 @@ describe('groups graphql test suite', () => { data: { groupByName }, }, } = await groupApi.groupByName(token, { - org_id: org01._id, + orgId: org01._id, name: 'group1' }); console.log(`get group by name: groupByName = ${JSON.stringify(groupByName)}`); @@ -477,7 +477,7 @@ describe('groups graphql test suite', () => { data: { group }, }, } = await groupApi.group(token, { - org_id: org01._id, + orgId: org01._id, uuid: group_02_uuid }); console.log(`get group by id: group = ${JSON.stringify(group)}`); diff --git a/app/apollo/test/groupApi.js b/app/apollo/test/groupApi.js index e27facdde..5cacdc487 100644 --- a/app/apollo/test/groupApi.js +++ b/app/apollo/test/groupApi.js @@ -22,13 +22,13 @@ const groupFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!) { - groups( org_id: $org_id ) { + query($orgId: String!) { + groups(orgId: $orgId ) { uuid - org_id + orgId name owner { - _id + id name } created @@ -49,8 +49,8 @@ const groupFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!, $uuid: String!) { - group( org_id: $org_id, uuid: $uuid ) { + query($orgId: String!, $uuid: String!) { + group( orgId: $orgId, uuid: $uuid ) { uuid clusterCount subscriptionCount @@ -73,8 +73,8 @@ const groupFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!, $name: String!) { - groupByName( org_id: $org_id, name: $name ) { + query($orgId: String!, $name: String!) { + groupByName( orgId: $orgId, name: $name ) { uuid clusterCount subscriptionCount diff --git a/app/apollo/test/organization.spec.js b/app/apollo/test/organization.spec.js index 81669a61b..9641a9564 100644 --- a/app/apollo/test/organization.spec.js +++ b/app/apollo/test/organization.spec.js @@ -110,10 +110,9 @@ describe('organization graphql test suite', () => { try { token = await signInUser(models, api, rootData); console.log(`root token=${token}`); - const meResult = await api.me(token); - const { org_id } = meResult.data.data.me; - const urlResult = await api.registrationUrl(token, { org_id }); + const { orgId } = meResult.data.data.me; + const urlResult = await api.registrationUrl(token, { orgId }); console.log(JSON.stringify(urlResult.data)); expect(urlResult.data.data.registrationUrl.url).to.be.a('string'); } catch (error) { @@ -138,16 +137,16 @@ describe('organization graphql test suite', () => { throw error; } }); - + it('a non-admin user should NOT be able to get registration url', async () => { try { token = await signInUser(models, api, user01Data); console.log(`user01 token=${token}`); const meResult = await api.me(token); - const { org_id } = meResult.data.data.me; + const { orgId } = meResult.data.data.me; - const urlResult = await api.registrationUrl(token, {org_id}); + const urlResult = await api.registrationUrl(token, {orgId}); console.log(JSON.stringify(urlResult.data)); expect(urlResult.data.errors[0].message).to.be.a('string'); diff --git a/app/apollo/test/resource.spec.js b/app/apollo/test/resource.spec.js index 001d3554a..f1b27a0d8 100644 --- a/app/apollo/test/resource.spec.js +++ b/app/apollo/test/resource.spec.js @@ -231,7 +231,7 @@ const createResources = async () => { const getPresetOrgs = async () => { presetOrgs = await models.Organization.find(); presetOrgs = presetOrgs.map(user => { - return user.toJSON(); + return user.toJSON({ virtuals: true }); }); console.log(`presetOrgs=${JSON.stringify(presetOrgs)}`); }; @@ -247,7 +247,7 @@ const getPresetUsers = async () => { const getPresetResources = async () => { presetResources = await models.Resource.find(); presetResources = presetResources.map(resource => { - return resource.toJSON(); + return resource.toJSON({ virtuals: true }); }); console.log(`presetResources=${JSON.stringify(presetResources)}`); }; @@ -295,17 +295,17 @@ describe('resource graphql test suite', () => { await mongoServer.stop(); }); - describe('resource(org_id: String!, _id: String!): Resource', () => { + describe('resource(orgId: String!, id: String!): Resource', () => { let token; - it('a user should see a resource by given _id', async () => { + it('a user should see a resource by given id', async () => { try { token = await signInUser(models, api, user01Data); console.log(`user01 token=${token}`); const meResult = await api.me(token); const result1 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'mybla', }); console.log(JSON.stringify(result1.data)); @@ -313,10 +313,10 @@ describe('resource graphql test suite', () => { '/mybla/selfLink', ); - const { _id } = result1.data.data.resources.resources[0]; - const result2 = await api.resource(token, { org_id: meResult.data.data.me.org_id, _id: _id.toString() }); + const { id } = result1.data.data.resources.resources[0]; + const result2 = await api.resource(token, { orgId: meResult.data.data.me.orgId, id: id.toString() }); console.log(JSON.stringify(result2.data)); - expect(result2.data.data.resource._id).to.equal(_id); + expect(result2.data.data.resource.id).to.equal(id); expect(result2.data.data.resource.selfLink).to.equal('/mybla/selfLink'); } catch (error) { // console.error('error response is ', error.response); @@ -335,7 +335,7 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'mybla', sort: [{ field: 'selfLink', desc: true }], }); @@ -344,7 +344,7 @@ describe('resource graphql test suite', () => { '/mybla/cluster04/selfLink2', ); const result2 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'mybla', sort: [{ field: 'selfLink' }], }); @@ -368,7 +368,7 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, kinds: ['Deployment'], }); console.log(JSON.stringify(result1.data)); @@ -379,7 +379,7 @@ describe('resource graphql test suite', () => { 1, ); const result2 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, kinds: ['StatefulSet'], }); console.log(JSON.stringify(result2.data)); @@ -406,8 +406,8 @@ describe('resource graphql test suite', () => { const result1 = await api.resourceHistId(token, { - _id: resourceObjId, - org_id: meResult.data.data.me.org_id, + id: resourceObjId, + orgId: meResult.data.data.me.orgId, filter: 'mybla', histId: 'resourceYamlHist_01', }); @@ -425,7 +425,7 @@ describe('resource graphql test suite', () => { }); }); - describe('resourceHistory(org_id: String!, cluster_id: String!, resourceSelfLink: String!, beforeDate: Date, afterDate: Date, limit: Int = 20)', ()=>{ + describe('resourceHistory(orgId: String!, clusterId: String!, resourceSelfLink: String!, beforeDate: Date, afterDate: Date, limit: Int = 20)', ()=>{ it('should view history list for a resource', async()=>{ let token; try { @@ -435,8 +435,8 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourceHistory(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01', resourceSelfLink: '/mybla/selfLink', beforeDate: null, afterDate: null, @@ -446,7 +446,7 @@ describe('resource graphql test suite', () => { expect(result1.data.data.resourceHistory.count).to.equal( 2 ); - var ids = _.map(result1.data.data.resourceHistory.items, '_id'); + var ids = _.map(result1.data.data.resourceHistory.items, 'id'); expect(ids.length).to.equal( 2 ); @@ -458,10 +458,10 @@ describe('resource graphql test suite', () => { }); }); - describe('resourceByKeys(org_id: String! cluster_id: String! selfLink: String!): Resource', () => { + describe('resourceByKeys(orgId: String! clusterId: String! selfLink: String!): Resource', () => { let token; - it('a user should see a resource by given org_id, cluster_id, and selfLink', async () => { + it('a user should see a resource by given orgId, clusterId, and selfLink', async () => { try { token = await signInUser(models, api, user01Data); @@ -470,12 +470,12 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourceByKeys(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01', selfLink: '/mybla/selfLink', }); console.log(JSON.stringify(result1.data)); - expect(result1.data.data.resourceByKeys.cluster_id).to.equal( + expect(result1.data.data.resourceByKeys.clusterId).to.equal( 'cluster_01', ); expect(result1.data.data.resourceByKeys.selfLink).to.equal( @@ -499,7 +499,7 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesCount(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, }); console.log(JSON.stringify(result1.data)); expect(result1.data.data.resourcesCount).to.equal(1); @@ -525,7 +525,7 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resources(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'mybla', }); console.log(JSON.stringify(result1.data)); @@ -540,10 +540,10 @@ describe('resource graphql test suite', () => { }); }); - describe('resourcesByCluster(cluster_id: String! filter: String): [Resource!]', () => { + describe('resourcesByCluster(clusterId: String! filter: String): [Resource!]', () => { let token; - it('a user should only see resources for given cluster_id with optional filter', async () => { + it('a user should only see resources for given clusterId with optional filter', async () => { try { token = await signInUser(models, api, user01Data); console.log(`user01 token=${token}`); @@ -551,12 +551,12 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesByCluster(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01', filter: 'selfLink', }); console.log(JSON.stringify(result1.data)); - expect(result1.data.data.resourcesByCluster.resources[0].cluster_id).to.equal( + expect(result1.data.data.resourcesByCluster.resources[0].clusterId).to.equal( 'cluster_01', ); expect(result1.data.data.resourcesByCluster.resources[0].selfLink).to.equal( @@ -570,8 +570,7 @@ describe('resource graphql test suite', () => { }); }); - - describe('resourcesBySubscription(org_id: String! filter: String): ResourcesList!', () => { + describe('resourcesBySubscription(orgId: String! filter: String): ResourcesList!', () => { let token; it('a user should only see resources for given subscription id', async () => { @@ -582,11 +581,11 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesBySubscription(token, { - org_id: meResult.data.data.me.org_id, - subscription_id: 'abc-123' + orgId: meResult.data.data.me.orgId, + subscriptionId: 'abc-123' }); console.log(JSON.stringify(result1.data)); - expect(result1.data.data.resourcesBySubscription.resources[0].cluster_id).to.equal( + expect(result1.data.data.resourcesBySubscription.resources[0].clusterId).to.equal( 'cluster_01', ); expect(result1.data.data.resourcesBySubscription.resources[0].searchableData.subscription_id).to.equal( @@ -600,7 +599,7 @@ describe('resource graphql test suite', () => { }); }); - describe('resourceUpdated (org_id: String!, filter: String): ResourceUpdated!', () => { + describe('resourceUpdated (orgId: String!, filter: String): ResourceUpdated!', () => { before(function() { if (pubSub.enabled === false) { // this.skip(); @@ -610,17 +609,17 @@ describe('resource graphql test suite', () => { let token; const aResource = { - _id: 'some_fake_id', - org_id: 'org_01', - cluster_id: 'cluster_01', + id: 'some_fake_id', + orgId: 'org_01', + clusterId: 'cluster_01', selfLink: '/ff/bla2', searchableData: { ttt: 'tt tt t1' }, }; const anotherResource = { - _id: 'anther_fake_id', - org_id: 'org_02', - cluster_id: 'cluster_01', + id: 'anther_fake_id', + orgId: 'org_02', + clusterId: 'cluster_01', selfLink: '/ff/bla2', searchableData: { ttt: 'tt tt t1' }, }; @@ -636,12 +635,12 @@ describe('resource graphql test suite', () => { wsUrl: subscriptionUrl, token, }); - const query = `subscription ($org_id: String!, $filter: String) { - resourceUpdated (org_id: $org_id, filter: $filter) { + const query = `subscription ($orgId: String!, $filter: String) { + resourceUpdated (orgId: $orgId, filter: $filter) { resource { - _id - org_id - cluster_id + id + orgId + clusterId selfLink hash searchableData @@ -655,12 +654,11 @@ describe('resource graphql test suite', () => { const meResult = await api.me(token); const unsub = subClient .request(query, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'bla2', }) .subscribe({ next: data => { - console.log(`sub handler receives:${JSON.stringify(data)}`); dataReceivedFromSub = data.data.resourceUpdated.resource; }, error: error => { @@ -671,14 +669,14 @@ describe('resource graphql test suite', () => { // sleep 0.1 second and send a resourceChanged event await sleep(200); - aResource.org_id = org_02._id; + aResource.orgId = org_02._id; // const result = await api.resourceChanged({r: aResource}); pubSub.resourceChangedFunc(aResource); // expect(result.data.data.resourceChanged._id).to.equal('some_fake_id'); // sleep another 0.1 second and verify if sub received the event await sleep(800); - expect(dataReceivedFromSub._id).to.equal('some_fake_id'); + expect(dataReceivedFromSub.id).to.equal('some_fake_id'); // sleep 0.1 second and send a resourceChanged event await sleep(100); diff --git a/app/apollo/test/resourceDistributed.spec.js b/app/apollo/test/resourceDistributed.spec.js index 26baa881e..0c6c26b95 100644 --- a/app/apollo/test/resourceDistributed.spec.js +++ b/app/apollo/test/resourceDistributed.spec.js @@ -172,7 +172,7 @@ describe('resourceDistributed graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesDistributed(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'mybla', }); console.log(JSON.stringify(result1.data)); @@ -180,16 +180,16 @@ describe('resourceDistributed graphql test suite', () => { '/mybla/selfLink', ); - const { _id } = result1.data.data.resourcesDistributed[0]; - const result2 = await api.resourceDistributed(token, { _id }); + const { id } = result1.data.data.resourcesDistributed[0]; + const result2 = await api.resourceDistributed(token, { id: id }); console.log(JSON.stringify(result2.data)); - expect(result2.data.data.resourceDistributed._id).to.equal(_id); + expect(result2.data.data.resourceDistributed.id).to.equal(id); expect(result2.data.data.resourceDistributed.selfLink).to.equal( '/mybla/selfLink', ); const result3 = await api.resourceDistributed(token, { - _id: '5deea2b9e7de2a430badbeef', + id: '5deea2b9e7de2a430badbeef', }); console.log(JSON.stringify(result3.data)); expect(result3.data.data.resourceDistributed).to.equal(null); @@ -212,12 +212,12 @@ describe('resourceDistributed graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourceDistributedByKeys(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01_in_us', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01_in_us', selfLink: 'any_selfLink', }); console.log(JSON.stringify(result1.data)); - expect(result1.data.data.resourceDistributedByKeys.cluster_id).to.equal( + expect(result1.data.data.resourceDistributedByKeys.clusterId).to.equal( 'cluster_01_in_us', ); expect(result1.data.data.resourceDistributedByKeys.selfLink).to.equal( @@ -225,8 +225,8 @@ describe('resourceDistributed graphql test suite', () => { ); const result2 = await api.resourceDistributedByKeys(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01_in_us', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01_in_us', selfLink: 'should_not_match_selfLink', }); console.log(JSON.stringify(result2.data)); @@ -250,7 +250,7 @@ describe('resourceDistributed graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesDistributedCount(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, }); console.log(JSON.stringify(result1.data)); expect(result1.data.data.resourcesDistributedCount).to.equal(2); @@ -273,7 +273,7 @@ describe('resourceDistributed graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesDistributed(token, { - org_id: meResult.data.data.me.org_id, + orgId: meResult.data.data.me.orgId, filter: 'selfLink', }); console.log(JSON.stringify(result1.data)); @@ -297,26 +297,26 @@ describe('resourceDistributed graphql test suite', () => { const meResult = await api.me(token); const result1 = await api.resourcesDistributedByCluster(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_01_in_us', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_01_in_us', filter: 'selfLink', }); console.log(JSON.stringify(result1.data)); expect( - result1.data.data.resourcesDistributedByCluster[0].cluster_id, + result1.data.data.resourcesDistributedByCluster[0].clusterId, ).to.equal('cluster_01_in_us'); expect( result1.data.data.resourcesDistributedByCluster[0].selfLink, ).to.equal('any_selfLink'); const result2 = await api.resourcesDistributedByCluster(token, { - org_id: meResult.data.data.me.org_id, - cluster_id: 'cluster_02_in_eu', + orgId: meResult.data.data.me.orgId, + clusterId: 'cluster_02_in_eu', filter: 'selfLink', }); console.log(JSON.stringify(result2.data)); expect( - result2.data.data.resourcesDistributedByCluster[0].cluster_id, + result2.data.data.resourcesDistributedByCluster[0].clusterId, ).to.equal('cluster_02_in_eu'); expect( result2.data.data.resourcesDistributedByCluster[0].selfLink, diff --git a/app/apollo/test/subscriptions.default.spec.js b/app/apollo/test/subscriptions.default.spec.js index 8844ed253..6ba2f1dfe 100644 --- a/app/apollo/test/subscriptions.default.spec.js +++ b/app/apollo/test/subscriptions.default.spec.js @@ -194,17 +194,18 @@ describe('subscriptions graphql test suite', () => { await mongoServer.stop(); }); // after - it('get should return a subscription for a cluster', async () => { + it('get should return a subscription for a cluster by calling deprecated subscriptionsByCluster', async () => { try { const { data: { data: { subscriptionsByCluster }, }, } = await subscriptionsApi.subscriptionsByCluster(token, { - cluster_id: cluster_id + cluster_id }, orgKey); expect(subscriptionsByCluster).to.have.length(1); + expect(subscriptionsByCluster[0].subscription_name).to.equal('fake_sub_01'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); @@ -215,7 +216,29 @@ describe('subscriptions graphql test suite', () => { } }); - it('get should return an empty array when there are no matching groups', async () => { + it('get should return a subscription for a cluster', async () => { + try { + const { + data: { + data: { subscriptionsByClusterId }, + }, + } = await subscriptionsApi.subscriptionsByClusterId(token, { + clusterId: cluster_id + }, orgKey); + + expect(subscriptionsByClusterId).to.have.length(1); + expect(subscriptionsByClusterId[0].subscriptionName).to.equal('fake_sub_01'); + } catch (error) { + if (error.response) { + console.error('error encountered: ', error.response.data); + } else { + console.error('error encountered: ', error); + } + throw error; + } + }); + + it('get should return an empty array when there are no matching groups by calling deprecated subscriptionsByCluster', async () => { try { const { data: { @@ -235,4 +258,24 @@ describe('subscriptions graphql test suite', () => { } }); + it('get should return an empty array when there are no matching groups', async () => { + try { + const { + data: { + data: { subscriptionsByClusterId }, + }, + } = await subscriptionsApi.subscriptionsByClusterId(token, { + clusterId: cluster_id_2 + }, orgKey); + expect(subscriptionsByClusterId).to.have.length(0); + } catch (error) { + if (error.response) { + console.error('error encountered: ', error.response.data); + } else { + console.error('error encountered: ', error); + } + throw error; + } + }); + }); diff --git a/app/apollo/test/subscriptions.spec.js b/app/apollo/test/subscriptions.spec.js index 27e8b9419..8f0d55600 100644 --- a/app/apollo/test/subscriptions.spec.js +++ b/app/apollo/test/subscriptions.spec.js @@ -292,7 +292,7 @@ describe('subscription graphql test suite', () => { data: { subscriptions }, }, } = await subscriptionApi.subscriptions(token, { - org_id: org01._id, + orgId: org01._id, }); expect(subscriptions).to.have.length(2); } catch (error) { @@ -312,7 +312,7 @@ describe('subscription graphql test suite', () => { data: { subscription }, }, } = await subscriptionApi.subscription(token, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_01_uuid, }); expect(subscription.name).to.equal(subscription_01_name); @@ -333,11 +333,11 @@ describe('subscription graphql test suite', () => { data: { addSubscription }, }, } = await subscriptionApi.addSubscription(adminToken, { - org_id: org01._id, + orgId: org01._id, name: 'a_random_name', groups:['dev'], - channel_uuid: channel_01_uuid, - version_uuid: channelVersion_01_uuid, + channelUuid: channel_01_uuid, + versionUuid: channelVersion_01_uuid, }); expect(addSubscription.uuid).to.be.an('string'); } catch (error) { @@ -358,12 +358,12 @@ describe('subscription graphql test suite', () => { data: { editSubscription }, }, } = await subscriptionApi.editSubscription(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_01_uuid, name: 'new-name', groups:['new-tag'], - channel_uuid: channel_02_uuid, - version_uuid: channelVersion_03_uuid, + channelUuid: channel_02_uuid, + versionUuid: channelVersion_03_uuid, }); expect(editSubscription.uuid).to.be.an('string'); expect(editSubscription.success).to.equal(true); @@ -373,12 +373,12 @@ describe('subscription graphql test suite', () => { data: { subscription }, }, } = await subscriptionApi.subscription(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_01_uuid, }); expect(subscription.name).to.equal('new-name'); - expect(subscription.channel_uuid).to.equal(channel_02_uuid); - expect(subscription.version_uuid).to.equal(channelVersion_03_uuid); + expect(subscription.channelUuid).to.equal(channel_02_uuid); + expect(subscription.versionUuid).to.equal(channelVersion_03_uuid); } catch (error) { if (error.response) { @@ -398,9 +398,9 @@ describe('subscription graphql test suite', () => { data: { setSubscription }, }, } = await subscriptionApi.setSubscription(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_02_uuid, - version_uuid: channelVersion_01_uuid, + versionUuid: channelVersion_01_uuid, }); expect(setSubscription.uuid).to.be.an('string'); expect(setSubscription.success).to.equal(true); @@ -410,10 +410,10 @@ describe('subscription graphql test suite', () => { data: { subscription }, }, } = await subscriptionApi.subscription(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_02_uuid, }); - expect(subscription.version_uuid).to.equal(channelVersion_01_uuid); + expect(subscription.versionUuid).to.equal(channelVersion_01_uuid); } catch (error) { if (error.response) { @@ -433,7 +433,7 @@ describe('subscription graphql test suite', () => { data: { removeSubscription }, }, } = await subscriptionApi.removeSubscriptions(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_01_uuid, }); expect(removeSubscription.uuid).to.be.an('string'); @@ -444,7 +444,7 @@ describe('subscription graphql test suite', () => { data: { subscription }, }, } = await subscriptionApi.subscription(adminToken, { - org_id: org01._id, + orgId: org01._id, uuid: subscription_01_uuid, }); expect(subscription).to.equal(null); diff --git a/app/apollo/test/subscriptionsApi.js b/app/apollo/test/subscriptionsApi.js index 10d731b6b..04f1c1152 100644 --- a/app/apollo/test/subscriptionsApi.js +++ b/app/apollo/test/subscriptionsApi.js @@ -41,25 +41,49 @@ const subscriptionsFunc = grahqlUrl => { }, }, ); + const subscriptionsByClusterId = async (token, variables, orgKey) => + axios.post( + grahqlUrl, + { + query: ` + query($clusterId: String!) { + subscriptionsByClusterId(clusterId: $clusterId) { + subscriptionName + subscriptionChannel + subscriptionUuid + subscriptionVersion + url + } + } + `, + variables, + }, + { + headers: { + Authorization: `Bearer ${token}`, + 'razee-org-key': orgKey + }, + }, + ); const subscriptions = async (token, variables) => axios.post( grahqlUrl, { query: ` - query($org_id: String!) { - subscriptions( org_id: $org_id) { + query($orgId: String!) { + subscriptions(orgId: $orgId) { uuid - org_id + orgId name groups - channel_uuid + channelUuid channel version - version_uuid + versionUuid created updated owner { - _id + id name } } @@ -79,20 +103,20 @@ const subscriptionsFunc = grahqlUrl => { grahqlUrl, { query: ` - query($org_id: String!, $uuid: String! ) { - subscription( org_id: $org_id uuid: $uuid ) { + query($orgId: String!, $uuid: String! ) { + subscription(orgId: $orgId uuid: $uuid ) { uuid - org_id + orgId name groups - channel_uuid + channelUuid channel version - version_uuid + versionUuid created updated owner { - _id + id name } } @@ -113,8 +137,8 @@ const subscriptionsFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $name: String!, $groups: [String!]!, $channel_uuid: String!, $version_uuid: String!) { - addSubscription(org_id: $org_id, name: $name, groups: $groups, channel_uuid: $channel_uuid, version_uuid: $version_uuid){ + mutation($orgId: String!, $name: String!, $groups: [String!]!, $channelUuid: String!, $versionUuid: String!) { + addSubscription(orgId: $orgId, name: $name, groups: $groups, channelUuid: $channelUuid, versionUuid: $versionUuid){ uuid } } @@ -133,8 +157,8 @@ const subscriptionsFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!, $name: String!, $groups: [String!]!, $channel_uuid: String!, $version_uuid: String!) { - editSubscription( org_id: $org_id, uuid: $uuid, name: $name, groups: $groups, channel_uuid: $channel_uuid, version_uuid: $version_uuid) { + mutation($orgId: String!, $uuid: String!, $name: String!, $groups: [String!]!, $channelUuid: String!, $versionUuid: String!) { + editSubscription(orgId: $orgId, uuid: $uuid, name: $name, groups: $groups, channelUuid: $channelUuid, versionUuid: $versionUuid) { uuid success } @@ -154,8 +178,8 @@ const subscriptionsFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!, $version_uuid: String!) { - setSubscription( org_id: $org_id, uuid: $uuid, version_uuid: $version_uuid) { + mutation($orgId: String!, $uuid: String!, $versionUuid: String!) { + setSubscription(orgId: $orgId, uuid: $uuid, versionUuid: $versionUuid) { uuid success } @@ -176,8 +200,8 @@ const subscriptionsFunc = grahqlUrl => { grahqlUrl, { query: ` - mutation($org_id: String!, $uuid: String!) { - removeSubscription( org_id: $org_id, uuid: $uuid) { + mutation($orgId: String!, $uuid: String!) { + removeSubscription(orgId: $orgId, uuid: $uuid) { uuid success } @@ -193,7 +217,8 @@ const subscriptionsFunc = grahqlUrl => { ); return { - subscriptionsByCluster, + subscriptionsByCluster, /* deprecated */ + subscriptionsByClusterId, subscriptions, subscription, addSubscription, diff --git a/app/apollo/test/testHelper.local.js b/app/apollo/test/testHelper.local.js index ba950a33e..703fed91d 100644 --- a/app/apollo/test/testHelper.local.js +++ b/app/apollo/test/testHelper.local.js @@ -50,7 +50,7 @@ async function signUpUser (models, api, userData) { username: userData.username, email: userData.email, password: userData.password, - org_name: userData.orgName, + orgName: userData.orgName, role: userData.role, }); return result0.data.data.signUp.token; diff --git a/app/apollo/test/user.spec.js b/app/apollo/test/user.spec.js index bbba81c33..6e8836d89 100644 --- a/app/apollo/test/user.spec.js +++ b/app/apollo/test/user.spec.js @@ -150,7 +150,7 @@ describe('user graphql', () => { expect(me.id).to.be.a('string'); expect(me.email).to.be.a('string'); - expect(me.org_id).to.be.a('string'); + expect(me.orgId).to.be.a('string'); } catch (error) { if (error.response) { console.error('error encountered: ', error.response.data); diff --git a/app/utils/subscriptions.js b/app/utils/subscriptions.js index 464ebe397..7773f3def 100644 --- a/app/utils/subscriptions.js +++ b/app/utils/subscriptions.js @@ -3,7 +3,7 @@ const { models } = require('../apollo/models'); const _ = require('lodash'); -const getSubscriptionUrls = async(orgId, matchingSubscriptions) => { +const getSubscriptionUrls = async(orgId, matchingSubscriptions, deprecated) => { const matchingChannels = await models.Channel.find({ org_id: orgId, @@ -22,11 +22,20 @@ const getSubscriptionUrls = async(orgId, matchingSubscriptions) => { if(foundVersion.length > 0) { url = `api/v1/channels/${subscription.channel}/${foundVersion[0].uuid}`; } + if (deprecated) { + return { + subscription_name: subscription.name, + subscription_channel: subscription.channel, + subscription_version: subscription.version, + subscription_uuid: subscription.uuid, + url: url + }; + } return { - subscription_name: subscription.name, - subscription_channel: subscription.channel, - subscription_version: subscription.version, - subscription_uuid: subscription.uuid, + subscriptionName: subscription.name, + subscriptionChannel: subscription.channel, + subscriptionVersion: subscription.version, + subscriptionUuid: subscription.uuid, url: url }; }); diff --git a/package-lock.json b/package-lock.json index bb27e4128..13af6dd07 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1443,6 +1443,15 @@ "integrity": "sha1-z+nYwmYoudxa7MYqn12PHzUsEZU=", "dev": true }, + "array.prototype.flat": { + "version": "1.2.3", + "resolved": "https://registry.npmjs.org/array.prototype.flat/-/array.prototype.flat-1.2.3.tgz", + "integrity": "sha512-gBlRZV0VSmfPIeWfuuy56XZMvbVfbEUnOXUvt3F/eUUUSyzlgLxhEX4YAEpxNAogRGehPSnfXyPtYyKAhkzQhQ==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1" + } + }, "array.prototype.map": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/array.prototype.map/-/array.prototype.map-1.0.2.tgz", @@ -5434,6 +5443,22 @@ } } }, + "mongoose-lean-virtuals": { + "version": "0.6.7", + "resolved": "https://registry.npmjs.org/mongoose-lean-virtuals/-/mongoose-lean-virtuals-0.6.7.tgz", + "integrity": "sha512-pl6j/B2TteXnx0zUCt3PpY7uANgJAzZzZiyK2QuLVYKg5rGCV6uwGliNbB5auAkY1WvG3SIY9jzVahwZSIn9ig==", + "requires": { + "array.prototype.flat": "1.2.3", + "mpath": "0.5.x" + }, + "dependencies": { + "mpath": { + "version": "0.5.2", + "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.5.2.tgz", + "integrity": "sha512-NOeCoW6AYc3hLi30npe7uzbD9b4FQZKH40YKABUCCvaKKL5agj6YzvHoNx8jQpDMNPgIa5bvSZQbQpWBAVD0Kw==" + } + } + }, "mongoose-legacy-pluralize": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", diff --git a/package.json b/package.json index 2f59a6d43..80f0ebe6d 100644 --- a/package.json +++ b/package.json @@ -66,6 +66,7 @@ "moment": "^2.26.0", "mongodb": "^3.5.9", "mongoose": "^5.9.18", + "mongoose-lean-virtuals": "^0.6.7", "mustache": "^4.0.1", "object-hash": "^2.0.3", "object-path": "^0.11.4",