import 'package:flutter_test/flutter_test.dart';
import 'package:tane/services/social_account_store.dart';

import '../support/test_support.dart';

void main() {
  test('defaults to account 0 with no max created yet', () async {
    final store = SocialAccountStore(InMemorySecretStore());
    expect(await store.active(), 0);
    expect(await store.maxCreated(), 0);
  });

  test('createNew increments the max and makes it active', () async {
    final store = SocialAccountStore(InMemorySecretStore());
    expect(await store.createNew(), 1);
    expect(await store.active(), 1);
    expect(await store.maxCreated(), 1);

    expect(await store.createNew(), 2);
    expect(await store.active(), 2);
    expect(await store.maxCreated(), 2);
  });

  test('setActive can switch back to an earlier identity, keeping the max',
      () async {
    final store = SocialAccountStore(InMemorySecretStore());
    await store.createNew(); // 1
    await store.createNew(); // 2
    await store.setActive(0); // back to the original
    expect(await store.active(), 0);
    expect(await store.maxCreated(), 2); // still remembers we made 3 identities
  });

  test('a negative account is rejected', () async {
    final store = SocialAccountStore(InMemorySecretStore());
    expect(() => store.setActive(-1), throwsArgumentError);
  });

  test('scope: account 0 uses legacy (empty) keys, others are namespaced', () {
    expect(socialAccountScope(0), '');
    expect(socialAccountScope(1), 'acct1');
    expect(socialAccountScope(2), 'acct2');
  });
}
