Skip to content

Commit

Permalink
tagIds to tag and use mockTag
Browse files Browse the repository at this point in the history
  • Loading branch information
kaulfield23 committed Nov 21, 2023
1 parent c5b8474 commit 0ab1990
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 21 deletions.
44 changes: 24 additions & 20 deletions src/features/import/utils/prepareImportOperation.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import mockTag from 'utils/testing/mocks/mockTag';
import { prepareImportOperations } from './prepareImportOperation';
import { ColumnKind, Sheet } from './types';
import { describe, it } from '@jest/globals';

describe('prepareImportOperations when first row is header', () => {
const mockingTag = mockTag();

it('converts ID only', () => {
const configData: Sheet = {
columns: [
Expand Down Expand Up @@ -104,8 +107,8 @@ describe('prepareImportOperations when first row is header', () => {
{
kind: ColumnKind.TAG,
mapping: [
{ tagIds: [233, 200], value: 'Frontend' },
{ tagIds: [234, 200], value: 'Backend' },
{ tags: [mockingTag], value: 'Frontend' },
{ tags: [mockingTag], value: 'Backend' },
],
selected: true,
},
Expand All @@ -130,11 +133,11 @@ describe('prepareImportOperations when first row is header', () => {
ops: [
{
op: 'person.import',
tags: [233, 200],
tags: [1],
},
{
op: 'person.import',
tags: [234, 200],
tags: [1],
},
],
});
Expand Down Expand Up @@ -208,8 +211,8 @@ describe('prepareImportOperations when first row is header', () => {
{
kind: ColumnKind.TAG,
mapping: [
{ tagIds: [233, 200], value: 'Frontend' },
{ tagIds: [234, 200], value: 'Backend' },
{ tags: [mockingTag], value: 'Frontend' },
{ tags: [mockingTag], value: 'Backend' },
],
selected: true,
},
Expand Down Expand Up @@ -247,7 +250,7 @@ describe('prepareImportOperations when first row is header', () => {
},
op: 'person.import',
organizations: [272],
tags: [233, 200],
tags: [1],
},
{
fields: {
Expand All @@ -257,7 +260,7 @@ describe('prepareImportOperations when first row is header', () => {
},
op: 'person.import',
organizations: [272, 100],
tags: [234, 200],
tags: [1],
},
],
});
Expand All @@ -279,8 +282,8 @@ describe('prepareImportOperations when first row is header', () => {
{
kind: ColumnKind.TAG,
mapping: [
{ tagIds: [233, 200], value: 'Frontend' },
{ tagIds: [234, 200], value: 'Backend' },
{ tags: [mockingTag], value: 'Frontend' },
{ tags: [mockingTag], value: 'Backend' },
],
selected: true,
},
Expand Down Expand Up @@ -309,7 +312,7 @@ describe('prepareImportOperations when first row is header', () => {
last_name: 'Doe',
},
op: 'person.import',
tags: [233, 200],
tags: [1],
},
{
fields: {
Expand All @@ -318,7 +321,7 @@ describe('prepareImportOperations when first row is header', () => {
last_name: 'Doe',
},
op: 'person.import',
tags: [234, 200],
tags: [1],
},
],
});
Expand All @@ -340,8 +343,8 @@ describe('prepareImportOperations when first row is header', () => {
{
kind: ColumnKind.TAG,
mapping: [
{ tagIds: [233, 200], value: 'Frontend' },
{ tagIds: [234, 200], value: 'Backend' },
{ tags: [mockingTag], value: 'Frontend' },
{ tags: [mockingTag], value: 'Backend' },
],
selected: true,
},
Expand Down Expand Up @@ -378,7 +381,7 @@ describe('prepareImportOperations when first row is header', () => {
},
op: 'person.import',
organizations: [272],
tags: [233, 200],
tags: [1],
},
{
fields: {
Expand All @@ -387,14 +390,15 @@ describe('prepareImportOperations when first row is header', () => {
},
op: 'person.import',
organizations: [272, 100],
tags: [234, 200],
tags: [1],
},
],
});
});
});

describe('prepareImportOperations when first row is not header', () => {
const mockingTag = mockTag();
it('converts ID, fields, tags and orgs', () => {
const configData: Sheet = {
columns: [
Expand All @@ -412,8 +416,8 @@ describe('prepareImportOperations when first row is not header', () => {
{
kind: ColumnKind.TAG,
mapping: [
{ tagIds: [233, 200], value: 'Frontend' },
{ tagIds: [234, 200], value: 'Backend' },
{ tags: [mockingTag], value: 'Frontend' },
{ tags: [mockingTag], value: 'Backend' },
],
selected: true,
},
Expand Down Expand Up @@ -448,7 +452,7 @@ describe('prepareImportOperations when first row is not header', () => {
},
op: 'person.import',
organizations: [272],
tags: [233, 200],
tags: [1],
},
{
fields: {
Expand All @@ -458,7 +462,7 @@ describe('prepareImportOperations when first row is not header', () => {
},
op: 'person.import',
organizations: [272, 100],
tags: [234, 200],
tags: [1],
},
],
});
Expand Down
4 changes: 3 additions & 1 deletion src/features/import/utils/prepareImportOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function prepareImportOperations(configData: Sheet): ImportOpsProp {
if (!result.ops[personIndex]) {
result.ops.push({ op: 'person.import', tags: [] });
}
result.ops[personIndex].tags = column.mapping[personIndex].tagIds;
result.ops[personIndex].tags = column.mapping[personIndex].tags.map(
(item) => item.id
);
}
if (column.kind === ColumnKind.ORGANIZATION) {
if (!result.ops[personIndex]) {
Expand Down

0 comments on commit 0ab1990

Please sign in to comment.