1212import com .squareup .square .labor .types .SearchShiftsRequest ;
1313import com .squareup .square .labor .types .UpdateBreakTypeRequest ;
1414import com .squareup .square .labor .types .UpdateShiftRequest ;
15+ import com .squareup .square .types .Location ;
16+ import com .squareup .square .types .SearchTeamMembersRequest ;
17+ import com .squareup .square .types .SearchTeamMembersQuery ;
18+ import com .squareup .square .types .SearchTeamMembersFilter ;
19+ import com .squareup .square .types .TeamMemberStatus ;
1520import com .squareup .square .types .BreakType ;
1621import com .squareup .square .types .CreateBreakTypeResponse ;
1722import com .squareup .square .types .CreateShiftResponse ;
18- import com .squareup .square .types .CreateTeamMemberRequest ;
19- import com .squareup .square .types .CreateTeamMemberResponse ;
2023import com .squareup .square .types .DeleteBreakTypeResponse ;
2124import com .squareup .square .types .DeleteShiftResponse ;
2225import com .squareup .square .types .GetBreakTypeResponse ;
2831import com .squareup .square .types .UpdateBreakTypeResponse ;
2932import com .squareup .square .types .UpdateShiftResponse ;
3033import com .squareup .square .types .WorkweekConfig ;
34+
3135import java .time .OffsetDateTime ;
3236import java .time .format .DateTimeFormatter ;
37+ import java .util .Collections ;
38+ import java .util .List ;
39+ import java .util .Optional ;
40+ import java .util .UUID ;
41+ import org .junit .jupiter .api .AfterEach ;
42+ import org .junit .jupiter .api .Assertions ;
43+ import org .junit .jupiter .api .BeforeEach ;
44+ import org .junit .jupiter .api .Test ;
45+ import java .util .List ;
3346import java .util .Optional ;
3447import java .util .UUID ;
3548import org .junit .jupiter .api .AfterEach ;
@@ -47,21 +60,32 @@ public class LaborTest {
4760 @ BeforeEach
4861 public void before () {
4962 client = TestClientFactory .create ();
50- locationId = Helpers .createLocation (client );
51-
52- // Create team member for testing
53- CreateTeamMemberResponse teamResponse = client .teamMembers ()
54- .create (CreateTeamMemberRequest .builder ()
55- .idempotencyKey (UUID .randomUUID ().toString ())
56- .teamMember (TeamMember .builder ()
57- .givenName ("Sherlock" )
58- .familyName ("Holmes" )
59- .build ())
60- .build ());
61- if (!teamResponse .getTeamMember ().get ().getId ().isPresent ()) {
62- throw new RuntimeException ("Failed to create team member." );
63+
64+ // Get first available location
65+ List <Location > locations = client .locations ().list ().getLocations ()
66+ .orElseThrow (() -> new RuntimeException ("No locations available" ));
67+ if (locations .isEmpty ()) {
68+ throw new RuntimeException ("No locations available for testing" );
6369 }
64- memberId = teamResponse .getTeamMember ().get ().getId ().get ();
70+ locationId = locations .get (0 ).getId ().orElseThrow (() -> new RuntimeException ("Location ID not present" ));
71+
72+ // Get first available team member at this location
73+ List <TeamMember > teamMembers = client .teamMembers ().search (
74+ SearchTeamMembersRequest .builder ()
75+ .query (SearchTeamMembersQuery .builder ()
76+ .filter (SearchTeamMembersFilter .builder ()
77+ .locationIds (Collections .singletonList (locationId ))
78+ .status (TeamMemberStatus .ACTIVE )
79+ .build ())
80+ .build ())
81+ .build ()
82+ ).getTeamMembers ()
83+ .orElseThrow (() -> new RuntimeException ("Failed to get team members" ));
84+
85+ if (teamMembers .isEmpty ()) {
86+ throw new RuntimeException ("No team members available at location " + locationId );
87+ }
88+ memberId = teamMembers .get (0 ).getId ().orElseThrow (() -> new RuntimeException ("Team member ID not present" ));
6589
6690 // Create break type for testing
6791 CreateBreakTypeResponse breakResponse = client .labor ()
@@ -210,28 +234,17 @@ public void testUpdateShift() {
210234
211235 @ Test
212236 public void testDeleteShift () {
213- // create team member
214- CreateTeamMemberResponse teamMemberResponse = client .teamMembers ()
215- .create (CreateTeamMemberRequest .builder ()
216- .idempotencyKey (UUID .randomUUID ().toString ())
217- .teamMember (TeamMember .builder ()
218- .givenName ("Sherlock" )
219- .familyName ("Holmes" )
220- .build ())
221- .build ());
222-
223237 // create shift
224238 CreateShiftResponse shiftResponse = client .labor ()
225- .shifts ()
226- .create (CreateShiftRequest .builder ()
227- .shift (Shift .builder ()
228- .locationId (locationId )
229- .startAt (OffsetDateTime .now ().format (DateTimeFormatter .ISO_INSTANT ))
230- .teamMemberId (
231- teamMemberResponse .getTeamMember ().get ().getId ())
232- .build ())
233- .idempotencyKey (UUID .randomUUID ().toString ())
234- .build ());
239+ .shifts ()
240+ .create (CreateShiftRequest .builder ()
241+ .shift (Shift .builder ()
242+ .locationId (locationId )
243+ .startAt (OffsetDateTime .now ().format (DateTimeFormatter .ISO_INSTANT ))
244+ .teamMemberId (memberId )
245+ .build ())
246+ .idempotencyKey (UUID .randomUUID ().toString ())
247+ .build ());
235248
236249 if (!shiftResponse .getShift ().isPresent ()) {
237250 throw new RuntimeException ("Failed to create shift." );
@@ -241,14 +254,14 @@ public void testDeleteShift() {
241254 }
242255 shiftId = shiftResponse .getShift ().get ().getId ().get ();
243256 DeleteShiftResponse response = client .labor ()
244- .shifts ()
245- .delete (DeleteShiftsRequest .builder ().id (shiftId ).build ());
257+ .shifts ()
258+ .delete (DeleteShiftsRequest .builder ().id (shiftId ).build ());
246259 Assertions .assertNotNull (response );
247260 }
248261
249262 @ Test
250263 public void testDeleteBreakType () {
251- // create break type
264+ // Create break type
252265 CreateBreakTypeResponse breakResponse = client .labor ()
253266 .breakTypes ()
254267 .create (CreateBreakTypeRequest .builder ()
@@ -268,11 +281,11 @@ public void testDeleteBreakType() {
268281 if (!breakType .get ().getId ().isPresent ()) {
269282 throw new RuntimeException ("Break ID is null." );
270283 }
271- breakId = breakType .get ().getId ().get ();
284+ String testBreakId = breakType .get ().getId ().get ();
272285
273286 DeleteBreakTypeResponse response = client .labor ()
274287 .breakTypes ()
275- .delete (DeleteBreakTypesRequest .builder ().id (breakId ).build ());
288+ .delete (DeleteBreakTypesRequest .builder ().id (testBreakId ).build ());
276289 Assertions .assertNotNull (response );
277290 }
278291
@@ -283,4 +296,4 @@ public void testListWorkweekConfigs() {
283296 .list (ListWorkweekConfigsRequest .builder ().build ());
284297 Assertions .assertFalse (response .getItems ().isEmpty ());
285298 }
286- }
299+ }
0 commit comments