Companies table (#79)
* Add columns to companies: * account_owner_id * employees * address Add foreign key constraint companies_account_owner_id_fkey to auth.users.id * Add select permissions to: * account_owner_id * employees * address Add relationship between companies and auth.users. * Update Companies interface to include: * account_owner_id * employees * address Opportunity is expected to be replace by actual opportunity in a separate PR. * Add GetCompanies query * Add initial companies table * Update test to use mock apollo provider * Update to match changed company column names * Add company interface mapping tests * Test entire object * Add test for companies being rendered in table. * Add test for sorting reduce. * Fix prettier errors
This commit is contained in:
68
front/src/interfaces/company.interface.test.ts
Normal file
68
front/src/interfaces/company.interface.test.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { mapGqlCompany, mapCompany } from './company.interface';
|
||||
|
||||
describe('mapCompany', () => {
|
||||
it('should map company', () => {
|
||||
const now = new Date();
|
||||
now.setMilliseconds(0);
|
||||
const company = mapCompany({
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||
name: 'ACME',
|
||||
domain_name: 'exmaple.com',
|
||||
created_at: now.toUTCString(),
|
||||
account_owner: {
|
||||
id: '7af20dea-0412-4c4c-8b13-d6f0e6e09e87',
|
||||
email: 'john@example.com',
|
||||
displayName: 'John Doe',
|
||||
},
|
||||
employees: 10,
|
||||
address: '1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
});
|
||||
expect(company.id).toBe('7dfbc3f7-6e5e-4128-957e-8d86808cdf6b');
|
||||
expect(company.name).toBe('ACME');
|
||||
expect(company.domain_name).toBe('exmaple.com');
|
||||
expect(company.creationDate).toEqual(now);
|
||||
expect(company.accountOwner.id).toBe(
|
||||
'7af20dea-0412-4c4c-8b13-d6f0e6e09e87',
|
||||
);
|
||||
expect(company.accountOwner.email).toBe('john@example.com');
|
||||
expect(company.accountOwner.first_name).toBe('John');
|
||||
expect(company.accountOwner.last_name).toBe('Doe');
|
||||
expect(company.employees).toBe(10);
|
||||
expect(company.address).toBe(
|
||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
);
|
||||
});
|
||||
|
||||
it('should map company back', () => {
|
||||
const now = new Date();
|
||||
now.setMilliseconds(0);
|
||||
const company = mapGqlCompany({
|
||||
id: '7dfbc3f7-6e5e-4128-957e-8d86808cdf6b',
|
||||
name: 'ACME',
|
||||
domain_name: 'exmaple.com',
|
||||
employees: 10,
|
||||
address: '1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
opportunities: [],
|
||||
accountOwner: {
|
||||
id: '522d4ec4-c46b-4360-a0a7-df8df170be81',
|
||||
email: 'john@example.com',
|
||||
first_name: 'John',
|
||||
last_name: 'Doe',
|
||||
},
|
||||
creationDate: now,
|
||||
});
|
||||
expect(company.id).toBe('7dfbc3f7-6e5e-4128-957e-8d86808cdf6b');
|
||||
expect(company.name).toBe('ACME');
|
||||
expect(company.domain_name).toBe('exmaple.com');
|
||||
expect(company.created_at).toEqual(now.toUTCString());
|
||||
expect(company.account_owner.id).toBe(
|
||||
'522d4ec4-c46b-4360-a0a7-df8df170be81',
|
||||
);
|
||||
expect(company.account_owner.email).toBe('john@example.com');
|
||||
expect(company.account_owner.displayName).toBe('John Doe');
|
||||
expect(company.employees).toBe(10);
|
||||
expect(company.address).toBe(
|
||||
'1 Infinite Loop, 95014 Cupertino, California, USA',
|
||||
);
|
||||
});
|
||||
});
|
||||
@ -1,5 +1,59 @@
|
||||
import { User } from './user.interface';
|
||||
|
||||
export interface Opportunity {
|
||||
name: string;
|
||||
icon: string;
|
||||
}
|
||||
|
||||
export interface Company {
|
||||
id: string;
|
||||
name: string;
|
||||
domain_name: string;
|
||||
employees: number;
|
||||
address: string;
|
||||
opportunities: Opportunity[];
|
||||
accountOwner: User;
|
||||
creationDate: Date;
|
||||
}
|
||||
|
||||
export type GraphqlQueryAccountOwner = {
|
||||
id: string;
|
||||
email: string;
|
||||
displayName: string;
|
||||
};
|
||||
|
||||
export type GraphqlQueryCompany = {
|
||||
id: string;
|
||||
name: string;
|
||||
domain_name: string;
|
||||
account_owner: GraphqlQueryAccountOwner;
|
||||
employees: number;
|
||||
address: string;
|
||||
created_at: string;
|
||||
};
|
||||
|
||||
export const mapCompany = (company: GraphqlQueryCompany): Company => ({
|
||||
...company,
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
accountOwner: {
|
||||
id: company.account_owner.id,
|
||||
email: company.account_owner.email,
|
||||
first_name: company.account_owner.displayName.split(' ').shift() || '',
|
||||
last_name: company.account_owner.displayName.split(' ').slice(1).join(' '),
|
||||
},
|
||||
creationDate: new Date(company.created_at),
|
||||
opportunities: [{ name: 'Sales Pipeline', icon: '' }],
|
||||
});
|
||||
|
||||
export const mapGqlCompany = (company: Company): GraphqlQueryCompany => ({
|
||||
...company,
|
||||
name: company.name,
|
||||
domain_name: company.domain_name,
|
||||
created_at: company.creationDate.toUTCString(),
|
||||
account_owner: {
|
||||
id: company.accountOwner.id,
|
||||
email: company.accountOwner.email,
|
||||
displayName: `${company.accountOwner.first_name} ${company.accountOwner.last_name}`,
|
||||
},
|
||||
});
|
||||
|
||||
@ -6,7 +6,10 @@ export type Person = {
|
||||
fullName: string;
|
||||
picture?: string;
|
||||
email: string;
|
||||
company: Company;
|
||||
company: Omit<
|
||||
Company,
|
||||
'employees' | 'address' | 'opportunities' | 'accountOwner' | 'creationDate'
|
||||
>;
|
||||
phone: string;
|
||||
creationDate: Date;
|
||||
pipe: Pipe;
|
||||
|
||||
Reference in New Issue
Block a user