Fix zapier (#2735)

* Fix zapier tests

* Handle nested fields

* Code review returns
This commit is contained in:
martmull
2023-11-27 18:09:21 +01:00
committed by GitHub
parent e2e871ca32
commit a413b29dd4
10 changed files with 137 additions and 80 deletions

View File

@ -12,15 +12,26 @@ import requestDb from '../utils/requestDb';
const appTester = createAppTester(App);
tools.env.inject();
const generateKey = async (z: ZObject, bundle: Bundle) => {
const createApiKey = async (z: ZObject, bundle: Bundle) => {
const query = `
mutation CreateApiKey {
createOneApiKey(
mutation createApiKey {
createApiKey(
data:{${handleQueryParams(bundle.inputData)}}
)
{id}
}`;
return (await requestDb(z, bundle, query)).data.createApiKey.id;
};
const generateApiKeyToken = async (z: ZObject, bundle: Bundle) => {
const query = `
mutation generateApiKeyToken {
generateApiKeyToken(
${handleQueryParams(bundle.inputData)}
)
{token}
}`;
return (await requestDb(z, bundle, query)).data.createOneApiKey.token;
return (await requestDb(z, bundle, query)).data.generateApiKeyToken.token;
};
describe('custom auth', () => {
@ -37,18 +48,24 @@ describe('custom auth', () => {
try {
await appTester(App.authentication.test, bundle);
} catch (error: any) {
expect(error.message).toContain('The API Key you supplied is incorrect');
expect(error.message).toContain('UNAUTHENTICATED');
return;
}
throw new Error('appTester should have thrown');
});
it('fails on invalid auth token', async () => {
const bundle = getBundle({
const expiresAt = '2020-01-01 10:10:10.000'
const apiKeyBundle = getBundle({
name: 'Test',
expiresAt: '2020-01-01 10:10:10.000',
expiresAt,
});
const expiredToken = await appTester(generateKey, bundle);
const apiKeyId = await appTester(createApiKey, apiKeyBundle);
const generateTokenBundle = getBundle({
apiKeyId: apiKeyId,
expiresAt,
});
const expiredToken = await appTester(generateApiKeyToken, generateTokenBundle);
const bundleWithExpiredApiKey = {
authData: { apiKey: expiredToken },
};
@ -56,7 +73,7 @@ describe('custom auth', () => {
try {
await appTester(App.authentication.test, bundleWithExpiredApiKey);
} catch (error: any) {
expect(error.message).toContain('The API Key you supplied is incorrect');
expect(error.message).toContain('UNAUTHENTICATED');
return;
}
throw new Error('appTester should have thrown');

View File

@ -11,9 +11,9 @@ describe('creates.create_company', () => {
name: 'Company Name',
address: 'Company Address',
domainName: 'Company Domain Name',
linkedinUrl: 'Test linkedinUrl',
xUrl: 'Test xUrl',
annualRecurringRevenue: 100000,
linkedinLink: {url: '/linkedin_url', label: "Test linkedinUrl"},
xLink: {url: '/x_url', label: "Test xUrl"},
annualRecurringRevenue: {amountMicros:100000000000,currencyCode: 'USD'},
idealCustomerProfile: true,
employees: 25,
});
@ -22,18 +22,18 @@ describe('creates.create_company', () => {
bundle,
);
expect(result).toBeDefined();
expect(result.data?.createOneCompany?.id).toBeDefined();
expect(result.data?.createCompany?.id).toBeDefined();
const checkDbResult = await appTester(
(z: ZObject, bundle: Bundle) =>
requestDb(
z,
bundle,
`query findCompany {findUniqueCompany(where: {id: "${result.data.createOneCompany.id}"}){id, annualRecurringRevenue}}`,
`query findCompany {company(filter: {id: {eq: "${result.data.createCompany.id}"}}){id annualRecurringRevenue{amountMicros currencyCode}}}`,
),
bundle,
);
expect(checkDbResult.data.findUniqueCompany.annualRecurringRevenue).toEqual(
100000,
expect(checkDbResult.data.company.annualRecurringRevenue.amountMicros).toEqual(
100000000000,
);
});
test('should run with not required missing params', async () => {
@ -41,8 +41,8 @@ describe('creates.create_company', () => {
name: 'Company Name',
address: 'Company Address',
domainName: 'Company Domain Name',
linkedinUrl: 'Test linkedinUrl',
xUrl: 'Test xUrl',
linkedinLink: {url: '/linkedin_url', label: "Test linkedinUrl"},
xLink: {url: '/x_url', label: "Test xUrl"},
idealCustomerProfile: true,
employees: 25,
});
@ -51,17 +51,17 @@ describe('creates.create_company', () => {
bundle,
);
expect(result).toBeDefined();
expect(result.data?.createOneCompany?.id).toBeDefined();
expect(result.data?.createCompany?.id).toBeDefined();
const checkDbResult = await appTester(
(z: ZObject, bundle: Bundle) =>
requestDb(
z,
bundle,
`query findCompany {findUniqueCompany(where: {id: "${result.data.createOneCompany.id}"}){id, annualRecurringRevenue}}`,
`query findCompany {company(filter: {id: {eq: "${result.data.createCompany.id}"}}){id annualRecurringRevenue{amountMicros currencyCode}}}`,
),
bundle,
);
expect(checkDbResult.data.findUniqueCompany.annualRecurringRevenue).toEqual(
expect(checkDbResult.data.company.annualRecurringRevenue.amountMicros).toEqual(
null,
);
});

View File

@ -8,8 +8,7 @@ tools.env.inject();
describe('creates.create_person', () => {
test('should run', async () => {
const bundle = getBundle({
firstName: 'John',
lastName: 'Doe',
name: {firstName: 'John', lastName: 'Doe'},
email: 'johndoe@gmail.com',
phone: '+33610203040',
city: 'Paris',
@ -19,23 +18,22 @@ describe('creates.create_person', () => {
bundle,
);
expect(results).toBeDefined();
expect(results.data?.createOnePerson?.id).toBeDefined();
expect(results.data?.createPerson?.id).toBeDefined();
const checkDbResult = await appTester(
(z: ZObject, bundle: Bundle) =>
requestDb(
z,
bundle,
`query findPerson {findUniquePerson(id: "${results.data.createOnePerson.id}"){id, phone}}`,
`query findPerson {person(filter: {id: {eq: "${results.data.createPerson.id}"}}){phone}}`,
),
bundle,
);
expect(checkDbResult.data.findUniquePerson.phone).toEqual('+33610203040');
expect(checkDbResult.data.person.phone).toEqual('+33610203040');
});
test('should run with not required missing params', async () => {
const bundle = getBundle({
firstName: 'John',
lastName: 'Doe',
name: {firstName: 'John', lastName: 'Doe'},
email: 'johndoe@gmail.com',
city: 'Paris',
});
@ -44,16 +42,16 @@ describe('creates.create_person', () => {
bundle,
);
expect(results).toBeDefined();
expect(results.data?.createOnePerson?.id).toBeDefined();
expect(results.data?.createPerson?.id).toBeDefined();
const checkDbResult = await appTester(
(z: ZObject, bundle: Bundle) =>
requestDb(
z,
bundle,
`query findPerson {findUniquePerson(id: "${results.data.createOnePerson.id}"){id, phone}}`,
`query findPerson {person(filter: {id: {eq: "${results.data.createPerson.id}"}}){phone}}`,
),
bundle,
);
expect(checkDbResult.data.findUniquePerson.phone).toEqual(null);
expect(checkDbResult.data.person.phone).toEqual("");
});
});

View File

@ -19,13 +19,12 @@ describe('triggers.company', () => {
requestDb(
z,
bundle,
`query findManyWebHook {findManyWebHook(where: {id: {equals: "${result.id}"}}){id operation}}`,
`query webhook {webhook(filter: {id: {eq: "${result.id}"}}){id operation}}`,
),
bundle,
);
expect(checkDbResult.data.findManyWebHook.length).toEqual(1);
expect(checkDbResult.data.findManyWebHook[0].operation).toEqual(
'createOneCompany',
expect(checkDbResult.data.webhook.operation).toEqual(
'company',
);
});
test('should succeed to unsubscribe', async () => {
@ -48,13 +47,13 @@ describe('triggers.company', () => {
requestDb(
z,
bundle,
`query findManyWebHook {findManyWebHook(where: {id: {equals: "${result.id}"}}){id}}`,
`query webhook {webhook(filter: {id: {eq: "${result.id}"}}){id}}`,
),
bundle,
);
expect(checkDbResult.data.findManyWebHook.length).toEqual(0);
expect(checkDbResult.data.webhook).toEqual(null);
});
test('should load company from web-hook', async () => {
test('should load company from webhook', async () => {
const bundle = {
cleanedRequest: {
id: 'd6ccb1d1-a90b-4822-a992-a0dd946592c9',
@ -85,6 +84,6 @@ describe('triggers.company', () => {
);
expect(results.length).toBeGreaterThan(1);
const firstCompany = results[0];
expect(firstCompany.id).toBeDefined();
expect(firstCompany.node.id).toBeDefined();
});
});

View File

@ -12,8 +12,10 @@ describe('utils.handleQueryParams', () => {
name: 'Company Name',
address: 'Company Address',
domainName: 'Company Domain Name',
linkedinUrl: 'Test linkedinUrl',
xUrl: 'Test xUrl',
linkedinUrl__url: '/linkedin_url',
linkedinUrl__label: "Test linkedinUrl",
xUrl__url: '/x_url',
xUrl__label: "Test xUrl",
annualRecurringRevenue: 100000,
idealCustomerProfile: true,
employees: 25,
@ -23,8 +25,8 @@ describe('utils.handleQueryParams', () => {
'name: "Company Name", ' +
'address: "Company Address", ' +
'domainName: "Company Domain Name", ' +
'linkedinUrl: "Test linkedinUrl", ' +
'xUrl: "Test xUrl", ' +
'linkedinUrl: {url: "/linkedin_url", label: "Test linkedinUrl"}, ' +
'xUrl: {url: "/x_url", label: "Test xUrl"}, ' +
'annualRecurringRevenue: 100000, ' +
'idealCustomerProfile: true, ' +
'employees: 25';