Skip to content

Commit

Permalink
Merge branch 'main' into crowd-linux
Browse files Browse the repository at this point in the history
  • Loading branch information
epipav committed Nov 14, 2023
2 parents afcf23a + 21bcd53 commit 38bbb1c
Show file tree
Hide file tree
Showing 33 changed files with 408 additions and 441 deletions.
3 changes: 1 addition & 2 deletions backend/src/api/organization/organizationCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import PermissionChecker from '../../services/user/permissionChecker'
export default async (req, res) => {
new PermissionChecker(req).validateHas(Permissions.values.organizationCreate)

const enrichP = req.body?.shouldEnrich || false
const payload = await new OrganizationService(req).createOrUpdate(req.body, enrichP)
const payload = await new OrganizationService(req).createOrUpdate(req.body)

track('Organization Manually Created', { ...payload }, { ...req })

Expand Down
4 changes: 2 additions & 2 deletions backend/src/database/initializers/suggested-tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
"body": "React to activities with very negative sentiment"
},
{
"name": "Setup your workpace integrations",
"name": "Set up your workpace integrations",
"body": "Connect with at least 2 data sources that are relevant to your community"
},
{
"name": "Setup your team",
"name": "Set up your team",
"body": "Invite colleagues to your community workspace"
}
]
115 changes: 1 addition & 114 deletions backend/src/services/__tests__/memberService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ describe('MemberService tests', () => {
})
})

it('Should create non existent member - organization as id, no enrichment', async () => {
it('Should create non existent member - organization as id', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(db)

const oCreated = await new OrganizationService(mockIServiceOptions).createOrUpdate({
Expand Down Expand Up @@ -793,119 +793,6 @@ describe('MemberService tests', () => {
})
})

it('Should create non existent member - organization with enrichment', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(
db,
Plans.values.growth,
)

const member1 = {
username: 'anil',
platform: PlatformType.GITHUB,
emails: ['[email protected]'],
score: 10,
attributes: {},
reach: 10,
bio: 'Computer Science',
organizations: [{ name: 'crowd.dev', url: 'https://crowd.dev', description: 'Here' }],
joinedAt: '2020-05-28T15:13:30Z',
location: 'Istanbul',
}

const memberCreated = await new MemberService(mockIServiceOptions).upsert(member1)

memberCreated.createdAt = memberCreated.createdAt.toISOString().split('T')[0]
memberCreated.updatedAt = memberCreated.updatedAt.toISOString().split('T')[0]

const organization = (await OrganizationRepository.findAndCountAll({}, mockIServiceOptions))
.rows[0]

const foundMember = await MemberRepository.findById(memberCreated.id, mockIServiceOptions)

const o1 = foundMember.organizations[0].get({ plain: true })
delete o1.createdAt
delete o1.updatedAt

expect(o1).toStrictEqual({
id: organization.id,
displayName: 'crowd.dev',
github: null,
location: null,
website: null,
description:
'Understand, grow, and engage your developer community with zero hassle. With crowd.dev, you can build developer communities that drive your business forward.',
emails: ['[email protected]', '[email protected]', '[email protected]'],
phoneNumbers: ['+42 424242'],
logo: 'https://logo.clearbit.com/crowd.dev',
memberOrganizations: {
dateEnd: null,
dateStart: null,
title: null,
source: null,
},
tags: [],
twitter: {
id: '1362101830923259908',
bio: 'Community-led Growth for Developer-first Companies.\nJoin our private beta. 👇',
site: 'https://t.co/GRLDhqFWk4',
avatar: 'https://pbs.twimg.com/profile_images/1419741008716251141/6exZe94-_normal.jpg',
handle: 'CrowdDotDev',
location: '🌍 remote',
followers: 107,
following: 0,
},
linkedin: {
handle: 'company/crowddevhq',
},
crunchbase: {
handle: null,
},
employees: 5,
revenueRange: {
max: 1,
min: 0,
},
importHash: null,
deletedAt: null,
tenantId: mockIServiceOptions.currentTenant.id,
createdById: mockIServiceOptions.currentUser.id,
updatedById: mockIServiceOptions.currentUser.id,
isTeamOrganization: false,
type: null,
ticker: null,
size: null,
naics: null,
lastEnrichedAt: null,
industry: null,
headline: null,
geoLocation: null,
founded: null,
employeeCountByCountry: null,
address: null,
profiles: null,
attributes: {},
manuallyCreated: false,
affiliatedProfiles: null,
allSubsidiaries: null,
alternativeDomains: null,
alternativeNames: null,
averageEmployeeTenure: null,
averageTenureByLevel: null,
averageTenureByRole: null,
directSubsidiaries: null,
employeeChurnRate: null,
employeeCountByMonth: null,
employeeGrowthRate: null,
employeeCountByMonthByLevel: null,
employeeCountByMonthByRole: null,
gicsSector: null,
grossAdditionsByMonth: null,
grossDeparturesByMonth: null,
ultimateParent: null,
immediateParent: null,
})
})

it('Should update existent member succesfully - simple', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(db)

Expand Down
185 changes: 2 additions & 183 deletions backend/src/services/__tests__/organizationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,6 @@ import OrganizationService from '../organizationService'

const db = null

const expectedEnriched = {
identities: [
{
name: 'crowd.dev',
platform: 'crowd',
},
],
description:
'Understand, grow, and engage your developer community with zero hassle. With crowd.dev, you can build developer communities that drive your business forward.',
emails: ['[email protected]', '[email protected]', '[email protected]'],
phoneNumbers: ['+42 424242'],
logo: 'https://logo.clearbit.com/crowd.dev',
tags: [],
twitter: {
handle: 'CrowdDotDev',
id: '1362101830923259908',
bio: 'Community-led Growth for Developer-first Companies.\nJoin our private beta. 👇',
followers: 107,
following: 0,
location: '🌍 remote',
site: 'https://t.co/GRLDhqFWk4',
avatar: 'https://pbs.twimg.com/profile_images/1419741008716251141/6exZe94-_normal.jpg',
},
linkedin: {
handle: 'company/crowddevhq',
},
crunchbase: {
handle: null,
},
employees: 5,
revenueRange: {
min: 0,
max: 1,
},
}

describe('OrganizationService tests', () => {
beforeEach(async () => {
await SequelizeTestUtils.wipeDatabase(db)
Expand All @@ -52,44 +16,7 @@ describe('OrganizationService tests', () => {
})

describe('Create method', () => {
it('Should add without enriching when enrichP is false', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(
db,
Plans.values.growth,
)
const service = new OrganizationService(mockIServiceOptions)

const toAdd = {
identities: [
{
name: 'crowd.dev',
platform: 'crowd',
},
],
}

const added = await service.createOrUpdate(toAdd, false)
expect(added.identities[0].url).toEqual(null)
})

it('Should add without enriching when tenant is not growth', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(db)
const service = new OrganizationService(mockIServiceOptions)

const toAdd = {
identities: [
{
name: 'crowd.dev',
platform: 'crowd',
},
],
}

const added = await service.createOrUpdate(toAdd, true)
expect(added.identities[0].url).toEqual(null)
})

it('Should enrich and add an organization by identity name', async () => {
it('Should create organization', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(
db,
Plans.values.growth,
Expand All @@ -101,120 +28,12 @@ describe('OrganizationService tests', () => {
{
name: 'crowd.dev',
platform: 'crowd',
url: 'https://crowd.dev',
},
],
}

const added = await service.createOrUpdate(toAdd)
expect(added.identities[0].url).toEqual(toAdd.identities[0].url)
expect(added.identities[0].name).toEqual(toAdd.identities[0].name)
expect(added.description).toEqual(expectedEnriched.description)
expect(added.emails).toEqual(expectedEnriched.emails)
expect(added.phoneNumbers).toEqual(expectedEnriched.phoneNumbers)
expect(added.logo).toEqual(expectedEnriched.logo)
expect(added.tags).toStrictEqual(expectedEnriched.tags)
expect(added.twitter).toStrictEqual(expectedEnriched.twitter)
expect(added.linkedin).toStrictEqual(expectedEnriched.linkedin)
expect(added.crunchbase).toStrictEqual(expectedEnriched.crunchbase)
expect(added.employees).toEqual(expectedEnriched.employees)
expect(added.revenueRange).toStrictEqual(expectedEnriched.revenueRange)

// Check cache table was created
const foundCache = await organizationCacheRepository.findByName(
'crowd.dev',
mockIServiceOptions,
)

expect(foundCache.url).toEqual('crowd.dev')
expect(foundCache.name).toEqual(toAdd.identities[0].name)
expect(foundCache.description).toEqual(expectedEnriched.description)
expect(foundCache.emails).toEqual(expectedEnriched.emails)
expect(foundCache.phoneNumbers).toEqual(expectedEnriched.phoneNumbers)
expect(foundCache.logo).toEqual(expectedEnriched.logo)
expect(foundCache.tags).toStrictEqual(expectedEnriched.tags)
expect(foundCache.twitter).toStrictEqual(expectedEnriched.twitter)
expect(foundCache.linkedin).toStrictEqual(expectedEnriched.linkedin)
expect(foundCache.crunchbase).toStrictEqual(expectedEnriched.crunchbase)
expect(foundCache.employees).toEqual(expectedEnriched.employees)
expect(foundCache.revenueRange).toStrictEqual(expectedEnriched.revenueRange)
})

it('Should not re-enrich when the record is already in the cache table. By Name', async () => {
const mockIServiceOptions = await SequelizeTestUtils.getTestIServiceOptions(
db,
Plans.values.growth,
)
const mockIServiceOptions2 = await SequelizeTestUtils.getTestIServiceOptions(
db,
Plans.values.growth,
)

const service = new OrganizationService(mockIServiceOptions)
const service2 = new OrganizationService(mockIServiceOptions2)

const toAdd = {
identities: [
{
name: 'crowd.dev',
platform: 'crowd',
url: 'https://crowd.dev',
},
],
}

const added = await service.createOrUpdate(toAdd)
expect(added.identities[0].url).toEqual(toAdd.identities[0].url)
expect(added.identities[0].name).toEqual(toAdd.identities[0].name)
expect(added.description).toEqual(expectedEnriched.description)
expect(added.emails).toEqual(expectedEnriched.emails)
expect(added.phoneNumbers).toEqual(expectedEnriched.phoneNumbers)
expect(added.logo).toEqual(expectedEnriched.logo)
expect(added.tags).toStrictEqual(expectedEnriched.tags)
expect(added.twitter).toStrictEqual(expectedEnriched.twitter)
expect(added.linkedin).toStrictEqual(expectedEnriched.linkedin)
expect(added.crunchbase).toStrictEqual(expectedEnriched.crunchbase)
expect(added.employees).toEqual(expectedEnriched.employees)
expect(added.revenueRange).toStrictEqual(expectedEnriched.revenueRange)

// Check cache table was created
const foundCache = await organizationCacheRepository.findByName(
'crowd.dev',
mockIServiceOptions,
)

expect(foundCache.name).toEqual('crowd.dev')
expect(foundCache.description).toEqual(expectedEnriched.description)
expect(foundCache.emails).toEqual(expectedEnriched.emails)
expect(foundCache.phoneNumbers).toEqual(expectedEnriched.phoneNumbers)
expect(foundCache.logo).toEqual(expectedEnriched.logo)
expect(foundCache.tags).toStrictEqual(expectedEnriched.tags)
expect(foundCache.twitter).toStrictEqual(expectedEnriched.twitter)
expect(foundCache.linkedin).toStrictEqual(expectedEnriched.linkedin)
expect(foundCache.crunchbase).toStrictEqual(expectedEnriched.crunchbase)
expect(foundCache.employees).toEqual(expectedEnriched.employees)
expect(foundCache.revenueRange).toStrictEqual(expectedEnriched.revenueRange)

const added2 = await service2.createOrUpdate(toAdd)
expect(added2.identities[0].url).toEqual(toAdd.identities[0].url)
expect(added2.description).toEqual(expectedEnriched.description)
expect(added2.emails).toEqual(expectedEnriched.emails)
expect(added2.phoneNumbers).toEqual(expectedEnriched.phoneNumbers)
expect(added2.logo).toEqual(expectedEnriched.logo)
expect(added2.tags).toStrictEqual(expectedEnriched.tags)
expect(added2.twitter).toStrictEqual(expectedEnriched.twitter)
expect(added2.linkedin).toStrictEqual(expectedEnriched.linkedin)
expect(added2.crunchbase).toStrictEqual(expectedEnriched.crunchbase)
expect(added2.employees).toEqual(expectedEnriched.employees)
expect(added2.revenueRange).toStrictEqual(expectedEnriched.revenueRange)
// Check they are indeed in different tenants
expect(added2.tenantId).not.toBe(added.tenantId)

const foundCache2 = await organizationCacheRepository.findByName(
'crowd.dev',
mockIServiceOptions,
)
expect(foundCache2.id).toEqual(foundCache.id)
expect(added.identities[0].url).toEqual(null)
})

it('Should throw an error when name is not sent', async () => {
Expand Down
4 changes: 2 additions & 2 deletions backend/src/services/activityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { LoggerBase, logExecutionTime } from '@crowd/logging'
import { Blob } from 'buffer'
import vader from 'crowd-sentiment'
import { Transaction } from 'sequelize/types'
import { FeatureFlag, PlatformType } from '@crowd/types'
import { FeatureFlag, PlatformType, SyncMode } from '@crowd/types'
import { WorkflowIdReusePolicy } from '@crowd/temporal'
import { IS_DEV_ENV, IS_TEST_ENV, GITHUB_CONFIG, TEMPORAL_CONFIG } from '../conf'
import ActivityRepository from '../database/repositories/activityRepository'
Expand Down Expand Up @@ -502,7 +502,7 @@ export default class ActivityService extends LoggerBase {

async createWithMember(data, fireCrowdWebhooks: boolean = true) {
const logger = this.options.log
const searchSyncService = new SearchSyncService(this.options)
const searchSyncService = new SearchSyncService(this.options, SyncMode.ASYNCHRONOUS)

const errorDetails: any = {}

Expand Down
Loading

0 comments on commit 38bbb1c

Please sign in to comment.