1515import com .squareup .square .types .BreakType ;
1616import com .squareup .square .types .CreateBreakTypeResponse ;
1717import com .squareup .square .types .CreateShiftResponse ;
18- import com .squareup .square .types .CreateTeamMemberRequest ;
19- import com .squareup .square .types .CreateTeamMemberResponse ;
2018import com .squareup .square .types .DeleteBreakTypeResponse ;
2119import com .squareup .square .types .DeleteShiftResponse ;
2220import com .squareup .square .types .GetBreakTypeResponse ;
@@ -47,21 +45,30 @@ public class LaborTest {
4745 @ BeforeEach
4846 public void before () {
4947 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." );
48+
49+ // Get first available location
50+ var locations = client .locations ().list ().getLocations ();
51+ if (locations == null || locations .isEmpty ()) {
52+ throw new RuntimeException ("No locations available for testing" );
53+ }
54+ locationId = locations .get (0 ).getId ();
55+
56+ // Get first available team member at this location
57+ var teamMembers = client .teamMembers ().search (
58+ com .squareup .square .team .types .SearchTeamMembersRequest .builder ()
59+ .query (com .squareup .square .team .types .SearchTeamMembersQuery .builder ()
60+ .filter (com .squareup .square .team .types .SearchTeamMembersFilter .builder ()
61+ .locationIds (java .util .Collections .singletonList (locationId ))
62+ .status ("ACTIVE" )
63+ .build ())
64+ .build ())
65+ .build ()
66+ ).getTeamMembers ();
67+
68+ if (teamMembers == null || teamMembers .isEmpty ()) {
69+ throw new RuntimeException ("No team members available at location " + locationId );
6370 }
64- memberId = teamResponse . getTeamMember (). get ().getId (). get ();
71+ memberId = teamMembers . get (0 ).getId ();
6572
6673 // Create break type for testing
6774 CreateBreakTypeResponse breakResponse = client .labor ()
@@ -210,25 +217,14 @@ public void testUpdateShift() {
210217
211218 @ Test
212219 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
220+ // Create shift
224221 CreateShiftResponse shiftResponse = client .labor ()
225222 .shifts ()
226223 .create (CreateShiftRequest .builder ()
227224 .shift (Shift .builder ()
228225 .locationId (locationId )
229226 .startAt (OffsetDateTime .now ().format (DateTimeFormatter .ISO_INSTANT ))
230- .teamMemberId (
231- teamMemberResponse .getTeamMember ().get ().getId ())
227+ .teamMemberId (memberId )
232228 .build ())
233229 .idempotencyKey (UUID .randomUUID ().toString ())
234230 .build ());
@@ -239,16 +235,16 @@ public void testDeleteShift() {
239235 if (!shiftResponse .getShift ().get ().getId ().isPresent ()) {
240236 throw new RuntimeException ("Shift ID is null." );
241237 }
242- shiftId = shiftResponse .getShift ().get ().getId ().get ();
238+ String testShiftId = shiftResponse .getShift ().get ().getId ().get ();
243239 DeleteShiftResponse response = client .labor ()
244240 .shifts ()
245- .delete (DeleteShiftsRequest .builder ().id (shiftId ).build ());
241+ .delete (DeleteShiftsRequest .builder ().id (testShiftId ).build ());
246242 Assertions .assertNotNull (response );
247243 }
248244
249245 @ Test
250246 public void testDeleteBreakType () {
251- // create break type
247+ // Create break type
252248 CreateBreakTypeResponse breakResponse = client .labor ()
253249 .breakTypes ()
254250 .create (CreateBreakTypeRequest .builder ()
@@ -268,11 +264,11 @@ public void testDeleteBreakType() {
268264 if (!breakType .get ().getId ().isPresent ()) {
269265 throw new RuntimeException ("Break ID is null." );
270266 }
271- breakId = breakType .get ().getId ().get ();
267+ String testBreakId = breakType .get ().getId ().get ();
272268
273269 DeleteBreakTypeResponse response = client .labor ()
274270 .breakTypes ()
275- .delete (DeleteBreakTypesRequest .builder ().id (breakId ).build ());
271+ .delete (DeleteBreakTypesRequest .builder ().id (testBreakId ).build ());
276272 Assertions .assertNotNull (response );
277273 }
278274
@@ -283,4 +279,4 @@ public void testListWorkweekConfigs() {
283279 .list (ListWorkweekConfigsRequest .builder ().build ());
284280 Assertions .assertFalse (response .getItems ().isEmpty ());
285281 }
286- }
282+ }
0 commit comments