Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
138 changes: 75 additions & 63 deletions lib/__tests__/transformer.spec.js
Original file line number Diff line number Diff line change
@@ -1,76 +1,88 @@
const expect = require('expect');
const { toGraphQLStruct } = require('../transformer');
const OntraportMockService = require('../mocks/ontraportApiMock');

const os = new OntraportMockService();
const getData = os.getObjectFields(0);

const createInput = async () => {
const mockData = await getData;

// make a copy
const fields = Object.assign({}, mockData.data[0].fields);

const file_data = {
code: 0,
data: {
'0': {
name: 'Contact',
fields: {
firstname: {
alias: 'First Name',
type: 'text',
required: '0',
unique: '0',
editable: '1',
deletable: '0',
},
lastname: {
alias: 'Last Name',
type: 'text',
required: '0',
unique: '0',
editable: '1',
deletable: '0',
},
email: {
alias: 'Email',
type: 'email',
required: '0',
unique: '1',
editable: '1',
deletable: '0',
},
id: {
alias: 'Contact ID',
type: 'numeric',
required: '0',
unique: '0',
editable: '0',
deletable: '0',
},
},
},
},
account_id: 168657,
// assign the name
const name = mockData.data[0].name;

return {
code: 0,
data: {
'0': {
name: name,
fields: {
firstname: fields.firstname,
lastname: fields.lastname,
email: fields.email,
id: fields.id,
},
},
},
account_id: 168657,
};
};

const contact = {
typeName: 'Contact',
defs: [
{ name: 'first_name', type: 'String!' },
{ name: 'last_name', type: 'String!' },
{ name: 'email', type: 'String!' },
{ name: 'id', type: 'Int!' },
],
const createOutput = () => {
return {
typeName: 'Contact',
defs: [
{ name: 'first_name', type: 'String!' },
{ name: 'last_name', type: 'String!' },
{ name: 'email', type: 'String!' },
{ name: 'id', type: 'Int!' },
],
};
};

describe('toGraphQLStruct Test Suit', () => {
const input = Object.assign({}, file_data); // make a clean copy
const output = { ...contact }; // make a clean copy
describe('Should describe the object', () => {
it(`toGraphQLStruct the input object should return a matching output object object`, async () => {
const input = await createInput();
const output = createOutput();
const result = await toGraphQLStruct({ ...input })[0];
return expect(result).toMatchObject(output);
});
});

it('toGraphQLStruct should be a function', () => {
expect(toGraphQLStruct).toBeInstanceOf(Function);
});
describe('Should describe the id', () => {
it(`id Should return of type Int!`, async () => {
const input = await createInput();
const output = createOutput();
const result = await toGraphQLStruct({ ...input })[0];
const id = await result.defs.find((obj) => obj.name === 'id');
return await expect(id.type).toBe('Int!');
});
});

// it('toGraphQLStruct should return an object', () => {
// expect(toGraphQLStruct({ ...input })).toBeInstanceOf(Object);
// });
describe('Should describe the firstname', () => {
it(`firstname Should return of type String!`, async () => {
const input = await createInput();
const output = createOutput();
const result = await toGraphQLStruct({ ...input })[0];
const firstname = await result.defs.find((obj) => obj.name === 'first_name');
return await expect(firstname.type).toBe('String!');
});
});

it(`In toGraphQLStruct, ${input} should return ${output}`, () => {
expect(toGraphQLStruct({ ...input })[0]).toMatchObject(output);
});
describe('Should describe the lastname', () => {
it(`lastname Should return of type String!`, async () => {
const input = await createInput();
const output = createOutput();
const result = await toGraphQLStruct({ ...input })[0];
const lastname = await result.defs.find((obj) => obj.name === 'last_name');
return await expect(lastname.type).toBe('String!');
});
});

describe('toGraphQLStruct Test Suit', () => {
it('toGraphQLStruct should be a function', () => {
expect(toGraphQLStruct).toBeInstanceOf(Function);
});
});
29 changes: 29 additions & 0 deletions lib/__tests__/translator.spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,34 @@
const expect = require('expect');
const { translateTypeKeys, translateFromType } = require('../translators');

const OntraportMockService = require('../mocks/ontraportApiMock');

// Start a mock session with mock data
describe('Testing the Translator with mock data', () => {
beforeAll(() => {
// instantiate a mock session
const os = new OntraportMockService();
const testObj = os.getOntraportObjects();
});

// Done with the test suit
afterAll(() => {
console.log('this test session is done');
});

// THE THINGS TO DO IN BETWEEN TESTS
beforeEach(() => {
console.log('Before a test');
});

afterEach(() => {
console.log('After a test');
});

// THE TESTS GO HERE
});

// Tests not using the mock data
describe('translateTypeKeys Test Suit', () => {
it('translateTypeKeys should be a function', () => {
expect(translateTypeKeys).toBeInstanceOf(Function);
Expand Down
Loading