@@ -5,25 +5,18 @@ const generateMutationQuery = require('../src/generate-mutation-query');
55const project = 'Backlog' ;
66const column = 'To do' ;
77const nodeId = 'MDU6SXNzdWU1ODc4NzU1Mjk=' ;
8- const data = {
8+
9+ const moveData = {
910 projectCards : {
1011 nodes : [
1112 {
1213 id : 'MDExOlByb2plY3RDYXJkMzUxNzI2MjM=' ,
1314 column : {
14- id : 'MDEzOlByb2plY3RDb2x1bW44MjUxODk4 '
15+ id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ6 '
1516 } ,
1617 project : {
17- name : project
18- }
19- } ,
20- {
21- id : 'MDExOlByb2plY3RDYXJkMzUxNzI2Mj2=' ,
22- column : {
23- id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5'
24- } ,
25- project : {
26- name : 'Backlogg'
18+ name : project ,
19+ id : 'MDc6UHJvamVjdDQwNzU5MDI='
2720 }
2821 }
2922 ]
@@ -37,24 +30,55 @@ const data = {
3730 columns : {
3831 nodes : [
3932 {
40- id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5 ' ,
41- name : column
33+ id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ6 ' ,
34+ name : 'Icebox'
4235 } ,
4336 {
44- id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ6 ' ,
45- name : 'To doo'
37+ id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5 ' ,
38+ name : column
4639 }
4740 ]
4841 }
49- } ,
42+ }
43+ ]
44+ } ,
45+ owner : {
46+ projects : {
47+ nodes : [ ]
48+ }
49+ }
50+ }
51+ } ;
52+
53+ test ( 'generateMutationQuery move the card when in the correct project and wrong column' , t => {
54+ t . deepEqual ( generateMutationQuery ( moveData , project , column , nodeId ) , [
55+ `mutation {
56+ moveProjectCard( input: {
57+ cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM=",
58+ columnId: "MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5"
59+ }) { clientMutationId } }`
60+ ] ) ;
61+ } ) ;
62+
63+ const addData = {
64+ projectCards : {
65+ nodes : [ ]
66+ } ,
67+ repository : {
68+ projects : {
69+ nodes : [
5070 {
51- id : 'MDc6UHJvamVjdDQwNzU5MDE=' ,
52- name : 'Backlogg ' ,
71+ name : project ,
72+ id : 'MDc6UHJvamVjdDQwNzU5MDI= ' ,
5373 columns : {
5474 nodes : [
5575 {
56- id : 'MDEzOlByb2plY3RDb2x1bW44MjUxODk7' ,
57- name : 'To do'
76+ id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5' ,
77+ name : column
78+ } ,
79+ {
80+ id : 'MDEzOlByb2plY3RDb2x1bW44MjUxOTAz' ,
81+ name : 'In progress'
5882 }
5983 ]
6084 }
@@ -63,57 +87,18 @@ const data = {
6387 } ,
6488 owner : {
6589 projects : {
66- nodes : [
67- {
68- id : 'MDc6UHJvamVjdDQwNzU5MDI=' ,
69- name : project ,
70- columns : {
71- nodes : [
72- {
73- id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ8' ,
74- name : column
75- } ,
76- {
77- id : 'MDEzOlByb2plY3RDb2x1bW44NDU0MzQ9' ,
78- name : 'In progress'
79- }
80- ]
81- }
82- } ,
83- {
84- id : 'MDc6UHJvamVjdDQwNzU5MDE=' ,
85- name : 'Backlogg' ,
86- columns : {
87- nodes : [
88- {
89- id : 'MDEzOlByb2plY3RDb2x1bW44MjUxOD10' ,
90- name : 'To do'
91- }
92- ]
93- }
94- }
95- ]
90+ nodes : [ ]
9691 }
9792 }
9893 }
9994} ;
10095
101- test ( 'findColumns should return column Ids for exact matches ' , t => {
102- t . deepEqual ( generateMutationQuery ( data , project , column , nodeId ) , [
96+ test ( 'generateMutationQuery add the card when the card does not exist in the project ' , t => {
97+ t . deepEqual ( generateMutationQuery ( addData , project , column , nodeId ) , [
10398 `mutation {
10499 addProjectCard( input: {
105100 contentId: "MDU6SXNzdWU1ODc4NzU1Mjk=",
106101 projectColumnId: "MDEzOlByb2plY3RDb2x1bW44NDU0MzQ5"
107- }) { clientMutationId } }` ,
108- `mutation {
109- addProjectCard( input: {
110- contentId: "MDU6SXNzdWU1ODc4NzU1Mjk=",
111- projectColumnId: "MDEzOlByb2plY3RDb2x1bW44NDU0MzQ8"
112- }) { clientMutationId } }` ,
113- `mutation {
114- moveProjectCard( input: {
115- cardId: "MDExOlByb2plY3RDYXJkMzUxNzI2MjM=",
116- columnId: "MDEzOlByb2plY3RDb2x1bW44MjUxODk4"
117102 }) { clientMutationId } }`
118103 ] ) ;
119104} ) ;
@@ -147,10 +132,10 @@ const dataNoColumn = {
147132 }
148133} ;
149134
150- test ( 'findColumns should fail if it cannot find a matching column' , t => {
135+ test ( 'generateMutationQuery should fail if it cannot find a matching column' , t => {
151136 const error = t . throws ( ( ) => generateMutationQuery ( dataNoColumn , project , column , nodeId ) ) ;
152137
153- t . is ( error . message , ' Could not find the column "To do" in project "Backlog"' ) ;
138+ t . is ( error . message , ` Could not find the column "${ column } " or project "${ project } "` ) ;
154139} ) ;
155140
156141const dataNoProject = {
@@ -182,8 +167,8 @@ const dataNoProject = {
182167 }
183168} ;
184169
185- test ( 'findColumns should fail if it cannot find a matching project' , t => {
170+ test ( 'generateMutationQuery should fail if it cannot find a matching project' , t => {
186171 const error = t . throws ( ( ) => generateMutationQuery ( dataNoProject , project , column , nodeId ) ) ;
187172
188- t . is ( error . message , ' Could not find the project "Backlog"' ) ;
173+ t . is ( error . message , ` Could not find the column " ${ column } " or project "${ project } "` ) ;
189174} ) ;
0 commit comments