Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default rules don't always appear to be set, although they clearly are... #122

Open
borgoat opened this issue Dec 31, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@borgoat
Copy link
Member

borgoat commented Dec 31, 2024

I tried to create a fake group to have some data to test the app, and found some buggy behaviour with default rules.

ScreenRecording_12-31-2024.10-20-56_1.MP4

(I didn't commit this because I didn't know where to place it.. I ran it as a test file, but if committed it would run for all tests... and I couldn't make it work as a standalone Dart file, I believe because it imports some Flutter stuff somewhere...)

import 'dart:math';

import 'package:faker/faker.dart';
import 'package:parousia/models/models.dart';
import 'package:parousia/repositories/repositories.dart';
import 'package:parousia/util/util.dart';
import 'package:rrule/rrule.dart';
import 'package:supabase/supabase.dart';

final SupabaseConfig config =
    SupabaseConfig.fromPath('supabase/config/localhost.json');

const authOptions = AuthClientOptions(authFlowType: AuthFlowType.implicit);

SupabaseClient supabaseAnonClient() =>
    SupabaseClient(config.apiUrl, config.anonKey, authOptions: authOptions);

void main() async {
  final supabase = supabaseAnonClient();
  await supabase.auth
      .signUp(password: 'password', email: faker.internet.email());
  final groupsRepository = GroupsRepository(supabase: supabase);
  final group = await groupsRepository.createGroup(
    Fake.group(),
  );

  final schedulesRepository = SchedulesRepository(supabase: supabase);

  final schedules = await Future.wait([
    for (var i = 0; i < 5; i++)
      schedulesRepository.createSchedule(Fake.schedule(groupId: group.id))
  ]);

  final membersRepository = MembersRepository(supabase: supabase);
  final members = await Future.wait([
    for (var i = 0; i < 15; i++)
      membersRepository.addMemberToGroup(group.id,
          displayName: faker.person.name())
  ]);

  final defaultRulesRepository = DefaultRulesRepository(supabase: supabase);

  ReplyOptions? randomReply() {
    if (Random().nextBool()) return null;
    final replies = ReplyOptions.values;
    return replies[Random().nextInt(replies.length)];
  }

  RecurrenceRule randomRecurrenceRule() {
    final n = Random().nextInt(5);
    switch (n) {
      case 0:
        return CommonRecurrenceRules.daily;
      case 1:
        return CommonRecurrenceRules.weekly;
      case 2:
        return CommonRecurrenceRules.monthly;
      case 3:
        return CommonRecurrenceRules.weekends;
      case 4:
        return CommonRecurrenceRules.weekdays;
      default:
        return CommonRecurrenceRules.daily;
    }
  }

  Future<DefaultRule?> createOptionalRandomDefaultRule(
      Schedule schedule, Member member) {
    final reply = randomReply();
    if (reply == null) return Future.value(null);

    final rule = randomRecurrenceRule();

    return defaultRulesRepository.createDefaultRule(DefaultRule(
        memberId: member.id,
        scheduleId: schedule.id,
        selectedOption: reply,
        recurrenceRule: rule));
  }

  final defaultRules = await Future.wait([
    for (final schedule in schedules)
      for (final member in members)
        createOptionalRandomDefaultRule(schedule, member)
  ]);

  final invitesRepository = InvitesRepository(supabase: supabase);
  final invites = await Future.wait([
    for (final member in members)
      invitesRepository.inviteWithGeneratedCode(member.id)
  ]);

  print('Use invite code ${invites.first.value} to join the group');
}
@borgoat borgoat added the bug Something isn't working label Dec 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant