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 ;
3339import java .util .Optional ;
3440import java .util .UUID ;
3541import org .junit .jupiter .api .AfterEach ;
@@ -47,21 +53,31 @@ public class LaborTest {
4753 @ BeforeEach
4854 public void before () {
4955 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." );
56+
57+ // Get first available location
58+ List <Location > locations = client .locations ().list ().getLocations ()
59+ .orElseThrow (() -> new RuntimeException ("No locations available" ));
60+ if (locations .isEmpty ()) {
61+ throw new RuntimeException ("No locations available for testing" );
62+ }
63+ locationId = locations .get (0 ).getId ().orElseThrow (() -> new RuntimeException ("Location ID not present" ));
64+
65+ // Get first available team member at this location
66+ List <TeamMember > teamMembers = client .teamMembers ().search (
67+ SearchTeamMembersRequest .builder ()
68+ .query (SearchTeamMembersQuery .builder ()
69+ .filter (SearchTeamMembersFilter .builder ()
70+ .locationIds (Collections .singletonList (locationId ))
71+ .status (TeamMemberStatus .ACTIVE )
72+ .build ())
73+ .build ())
74+ .build ()
75+ ).getTeamMembers ();
76+
77+ if (teamMembers == null || teamMembers .isEmpty ()) {
78+ throw new RuntimeException ("No team members available at location " + locationId );
6379 }
64- memberId = teamResponse . getTeamMember (). get ().getId ().get ( );
80+ memberId = teamMembers . get (0 ).getId ().orElseThrow (() -> new RuntimeException ( "Team member ID not present" ) );
6581
6682 // Create break type for testing
6783 CreateBreakTypeResponse breakResponse = client .labor ()
@@ -210,25 +226,14 @@ public void testUpdateShift() {
210226
211227 @ Test
212228 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-
223- // create shift
229+ // Create shift
224230 CreateShiftResponse shiftResponse = client .labor ()
225231 .shifts ()
226232 .create (CreateShiftRequest .builder ()
227233 .shift (Shift .builder ()
228234 .locationId (locationId )
229235 .startAt (OffsetDateTime .now ().format (DateTimeFormatter .ISO_INSTANT ))
230- .teamMemberId (
231- teamMemberResponse .getTeamMember ().get ().getId ())
236+ .teamMemberId (memberId )
232237 .build ())
233238 .idempotencyKey (UUID .randomUUID ().toString ())
234239 .build ());
@@ -239,16 +244,16 @@ public void testDeleteShift() {
239244 if (!shiftResponse .getShift ().get ().getId ().isPresent ()) {
240245 throw new RuntimeException ("Shift ID is null." );
241246 }
242- shiftId = shiftResponse .getShift ().get ().getId ().get ();
247+ String testShiftId = shiftResponse .getShift ().get ().getId ().get ();
243248 DeleteShiftResponse response = client .labor ()
244249 .shifts ()
245- .delete (DeleteShiftsRequest .builder ().id (shiftId ).build ());
250+ .delete (DeleteShiftsRequest .builder ().id (testShiftId ).build ());
246251 Assertions .assertNotNull (response );
247252 }
248253
249254 @ Test
250255 public void testDeleteBreakType () {
251- // create break type
256+ // Create break type
252257 CreateBreakTypeResponse breakResponse = client .labor ()
253258 .breakTypes ()
254259 .create (CreateBreakTypeRequest .builder ()
@@ -268,11 +273,11 @@ public void testDeleteBreakType() {
268273 if (!breakType .get ().getId ().isPresent ()) {
269274 throw new RuntimeException ("Break ID is null." );
270275 }
271- breakId = breakType .get ().getId ().get ();
276+ String testBreakId = breakType .get ().getId ().get ();
272277
273278 DeleteBreakTypeResponse response = client .labor ()
274279 .breakTypes ()
275- .delete (DeleteBreakTypesRequest .builder ().id (breakId ).build ());
280+ .delete (DeleteBreakTypesRequest .builder ().id (testBreakId ).build ());
276281 Assertions .assertNotNull (response );
277282 }
278283
@@ -283,4 +288,4 @@ public void testListWorkweekConfigs() {
283288 .list (ListWorkweekConfigsRequest .builder ().build ());
284289 Assertions .assertFalse (response .getItems ().isEmpty ());
285290 }
286- }
291+ }
0 commit comments