import 'package:new_backend/shrink_ray.dart';
import 'package:test/test.dart';

void main() {
  test('ShrinkRay equal urls get converted to the same shrunk url', () {
    const ytUrl = 'https://youtube.com';
    final ytRes = ShrinkRay.shrinkUrl(ytUrl);
    final ytRes2 = ShrinkRay.shrinkUrl(ytUrl);
    expect(ytRes.status, ytRes2.status);
    expect(ytRes.content, ytRes2.content);

    const startSearchUrl = 'https://www.startpage.com/sp/search?query=how+to+be+awesome';
    final startSearchRes = ShrinkRay.shrinkUrl(startSearchUrl);
    final startSearchRes2 = ShrinkRay.shrinkUrl(startSearchUrl);
    expect(startSearchRes.status, startSearchRes2.status);
    expect(startSearchRes.content, startSearchRes2.content);
  });

  test('ShrinkRay invalid Urls return error status and message', () {
    const badScheme = 'ht://google.com';
    final schemeRes = ShrinkRay.shrinkUrl(badScheme);
    expect(schemeRes.status, Status.error);

    const badUrl = 'hello world';
    final urlRes = ShrinkRay.shrinkUrl(badUrl);
    expect(urlRes.status, Status.error);

    const badPort = 'http://fosscat.com:1234';
    final portRes = ShrinkRay.shrinkUrl(badPort);
    expect(portRes.status, Status.error);
  });
}
