Removed Test Folder

This commit is contained in:
thomashii 2022-01-02 15:27:06 +08:00
parent 630b301555
commit c5286ea623
8 changed files with 0 additions and 1904 deletions

View file

@ -1 +0,0 @@
include: package:lints/recommended.yaml

View file

@ -1,175 +0,0 @@
import 'dart:async';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:test/test.dart';
import 'models/book.dart';
import 'util.dart';
void belongsToTests(FutureOr<QueryExecutor> Function() createExecutor,
{FutureOr<void> Function(QueryExecutor)? close}) {
late QueryExecutor executor;
Author? jkRowling;
Author? jameson;
Book? deathlyHallows;
close ??= (_) => null;
setUp(() async {
executor = await createExecutor();
// Insert an author
var query = AuthorQuery()..values.name = 'J.K. Rowling';
jkRowling = (await query.insert(executor)).value;
query.values.name = 'J.K. Jameson';
jameson = (await query.insert(executor)).value;
// And a book
var bookQuery = BookQuery();
bookQuery.values
..authorId = jkRowling!.idAsInt
..partnerAuthorId = jameson!.idAsInt
..name = 'Deathly Hallows';
deathlyHallows = (await bookQuery.insert(executor)).value;
});
tearDown(() => close!(executor));
group('selects', () {
test('select all', () async {
var query = BookQuery();
var books = await query.get(executor);
expect(books, hasLength(1));
var book = books.first;
//print(book.toJson());
expect(book.id, deathlyHallows!.id);
expect(book.name, deathlyHallows!.name);
var author = book.author!;
//print(AuthorSerializer.toMap(author));
expect(author.id, jkRowling!.id);
expect(author.name, jkRowling!.name);
});
test('select one', () async {
var query = BookQuery();
query.where!.id.equals(int.parse(deathlyHallows!.id!));
//print(query.compile({}));
var bookOpt = await query.getOne(executor);
expect(bookOpt.isPresent, true);
bookOpt.ifPresent((book) {
//print(book.toJson());
expect(book.id, deathlyHallows!.id);
expect(book.name, deathlyHallows!.name);
var author = book.author!;
//print(AuthorSerializer.toMap(author));
expect(author.id, jkRowling!.id);
expect(author.name, jkRowling!.name);
});
});
test('where clause', () async {
var query = BookQuery()
..where!.name.equals('Goblet of Fire')
..orWhere((w) => w.authorId.equals(jkRowling!.idAsInt));
//print(query.compile({}));
var books = await query.get(executor);
expect(books, hasLength(1));
var book = books.first;
//print(book.toJson());
expect(book.id, deathlyHallows!.id);
expect(book.name, deathlyHallows!.name);
var author = book.author!;
//print(AuthorSerializer.toMap(author));
expect(author.id, jkRowling!.id);
expect(author.name, jkRowling!.name);
});
test('union', () async {
var query1 = BookQuery()..where!.name.like('Deathly%');
var query2 = BookQuery()..where!.authorId.equals(-1);
var query3 = BookQuery()
..where!.name.isIn(['Goblet of Fire', 'Order of the Phoenix']);
query1
..union(query2)
..unionAll(query3);
//print(query1.compile({}));
var books = await query1.get(executor);
expect(books, hasLength(1));
var book = books.first;
//print(book.toJson());
expect(book.id, deathlyHallows!.id);
expect(book.name, deathlyHallows!.name);
var author = book.author!;
//print(AuthorSerializer.toMap(author));
expect(author.id, jkRowling!.id);
expect(author.name, jkRowling!.name);
});
test('order by', () async {
var query = AuthorQuery()..orderBy(AuthorFields.name, descending: true);
var authors = await query.get(executor);
expect(authors, [jkRowling, jameson]);
});
});
test('insert sets relationship', () {
expect(deathlyHallows!.author, jkRowling);
//expect(deathlyHallows.author, isNotNull);
//expect(deathlyHallows.author.name, rowling.name);
});
test('delete stream', () async {
//printSeparator('Delete stream test');
var query = BookQuery()..where!.name.equals(deathlyHallows!.name!);
//print(query.compile({}, preamble: 'DELETE', withFields: false));
var books = await query.delete(executor);
expect(books, hasLength(1));
var book = books.first;
expect(book.id, deathlyHallows?.id);
expect(book.author, isNotNull);
expect(book.author!.name, jkRowling!.name);
});
test('update book', () async {
var cloned = deathlyHallows!.copyWith(name: "Sorcerer's Stone");
var query = BookQuery()
..where?.id.equals(int.parse(cloned.id!))
..values.copyFrom(cloned);
var bookOpt = await (query.updateOne(executor));
expect(bookOpt.isPresent, true);
bookOpt.ifPresent((book) {
//print(book.toJson());
expect(book.name, cloned.name);
expect(book.author, isNotNull);
expect(book.author!.name, jkRowling!.name);
});
});
group('joined subquery', () {
// To verify that the joined subquery is correct,
// we test both a query that return empty, and one
// that should return correctly.
test('returns empty on false subquery', () async {
printSeparator('False subquery test');
var query = BookQuery()..author.where!.name.equals('Billie Jean');
expect(await query.get(executor), isEmpty);
});
test('returns values on true subquery', () async {
printSeparator('True subquery test');
var query = BookQuery()..author.where!.name.like('%Rowling%');
expect(await query.get(executor), [deathlyHallows]);
});
});
}

View file

@ -1,28 +0,0 @@
library angel_orm3.generator.models.book;
import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:optional/optional.dart';
part 'book.g.dart';
@serializable
@orm
class _Book extends Model {
@BelongsTo(joinType: JoinType.inner)
_Author? author;
@BelongsTo(localKey: 'partner_author_id', joinType: JoinType.inner)
_Author? partnerAuthor;
String? name;
}
@serializable
@orm
abstract class _Author extends Model {
@Column(length: 255, indexType: IndexType.unique)
@SerializableField(defaultValue: 'Tobe Osakwe')
String? get name;
}

View file

@ -1,617 +0,0 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of angel_orm3.generator.models.book;
// **************************************************************************
// MigrationGenerator
// **************************************************************************
class BookMigration extends Migration {
@override
void up(Schema schema) {
schema.create('books', (table) {
table.serial('id').primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('name', length: 255);
table.declare('author_id', ColumnType('int')).references('authors', 'id');
table
.declare('partner_author_id', ColumnType('int'))
.references('authors', 'id');
});
}
@override
void down(Schema schema) {
schema.drop('books');
}
}
class AuthorMigration extends Migration {
@override
void up(Schema schema) {
schema.create('authors', (table) {
table.serial('id').primaryKey();
table.timeStamp('created_at');
table.timeStamp('updated_at');
table.varChar('name', length: 255)
..defaultsTo('Tobe Osakwe')
..unique();
});
}
@override
void down(Schema schema) {
schema.drop('authors');
}
}
// **************************************************************************
// OrmGenerator
// **************************************************************************
class BookQuery extends Query<Book, BookQueryWhere> {
BookQuery({Query? parent, Set<String>? trampoline}) : super(parent: parent) {
trampoline ??= <String>{};
trampoline.add(tableName);
_where = BookQueryWhere(this);
join(_author = AuthorQuery(trampoline: trampoline, parent: this),
'author_id', 'id',
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline);
join(_partnerAuthor = AuthorQuery(trampoline: trampoline, parent: this),
'partner_author_id', 'id',
additionalFields: const ['id', 'created_at', 'updated_at', 'name'],
trampoline: trampoline);
}
@override
final BookQueryValues values = BookQueryValues();
BookQueryWhere? _where;
late AuthorQuery _author;
late AuthorQuery _partnerAuthor;
@override
Map<String, String> get casts {
return {};
}
@override
String get tableName {
return 'books';
}
@override
List<String> get fields {
return const [
'id',
'created_at',
'updated_at',
'author_id',
'partner_author_id',
'name'
];
}
@override
BookQueryWhere? get where {
return _where;
}
@override
BookQueryWhere newWhereClause() {
return BookQueryWhere(this);
}
static Optional<Book> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Book(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[5] as String?));
if (row.length > 6) {
var modelOpt = AuthorQuery.parseRow(row.skip(6).take(4).toList());
modelOpt.ifPresent((m) {
model = model.copyWith(author: m);
});
}
if (row.length > 10) {
var modelOpt = AuthorQuery.parseRow(row.skip(10).take(4).toList());
modelOpt.ifPresent((m) {
model = model.copyWith(partnerAuthor: m);
});
}
return Optional.of(model);
}
@override
Optional<Book> deserialize(List row) {
return parseRow(row);
}
AuthorQuery get author {
return _author;
}
AuthorQuery get partnerAuthor {
return _partnerAuthor;
}
}
class BookQueryWhere extends QueryWhere {
BookQueryWhere(BookQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
authorId = NumericSqlExpressionBuilder<int>(query, 'author_id'),
partnerAuthorId =
NumericSqlExpressionBuilder<int>(query, 'partner_author_id'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final NumericSqlExpressionBuilder<int> authorId;
final NumericSqlExpressionBuilder<int> partnerAuthorId;
final StringSqlExpressionBuilder name;
@override
List<SqlExpressionBuilder> get expressionBuilders {
return [id, createdAt, updatedAt, authorId, partnerAuthorId, name];
}
}
class BookQueryValues extends MapQueryValues {
@override
Map<String, String> get casts {
return {};
}
String? get id {
return (values['id'] as String?);
}
set id(String? value) => values['id'] = value;
DateTime? get createdAt {
return (values['created_at'] as DateTime?);
}
set createdAt(DateTime? value) => values['created_at'] = value;
DateTime? get updatedAt {
return (values['updated_at'] as DateTime?);
}
set updatedAt(DateTime? value) => values['updated_at'] = value;
int get authorId {
return (values['author_id'] as int);
}
set authorId(int value) => values['author_id'] = value;
int get partnerAuthorId {
return (values['partner_author_id'] as int);
}
set partnerAuthorId(int value) => values['partner_author_id'] = value;
String? get name {
return (values['name'] as String?);
}
set name(String? value) => values['name'] = value;
void copyFrom(Book model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
name = model.name;
if (model.author != null) {
values['author_id'] = model.author?.id;
}
if (model.partnerAuthor != null) {
values['partner_author_id'] = model.partnerAuthor?.id;
}
}
}
class AuthorQuery extends Query<Author, AuthorQueryWhere> {
AuthorQuery({Query? parent, Set<String>? trampoline})
: super(parent: parent) {
trampoline ??= <String>{};
trampoline.add(tableName);
_where = AuthorQueryWhere(this);
}
@override
final AuthorQueryValues values = AuthorQueryValues();
AuthorQueryWhere? _where;
@override
Map<String, String> get casts {
return {};
}
@override
String get tableName {
return 'authors';
}
@override
List<String> get fields {
return const ['id', 'created_at', 'updated_at', 'name'];
}
@override
AuthorQueryWhere? get where {
return _where;
}
@override
AuthorQueryWhere newWhereClause() {
return AuthorQueryWhere(this);
}
static Optional<Author> parseRow(List row) {
if (row.every((x) => x == null)) {
return Optional.empty();
}
var model = Author(
id: row[0].toString(),
createdAt: (row[1] as DateTime?),
updatedAt: (row[2] as DateTime?),
name: (row[3] as String?));
return Optional.of(model);
}
@override
Optional<Author> deserialize(List row) {
return parseRow(row);
}
}
class AuthorQueryWhere extends QueryWhere {
AuthorQueryWhere(AuthorQuery query)
: id = NumericSqlExpressionBuilder<int>(query, 'id'),
createdAt = DateTimeSqlExpressionBuilder(query, 'created_at'),
updatedAt = DateTimeSqlExpressionBuilder(query, 'updated_at'),
name = StringSqlExpressionBuilder(query, 'name');
final NumericSqlExpressionBuilder<int> id;
final DateTimeSqlExpressionBuilder createdAt;
final DateTimeSqlExpressionBuilder updatedAt;
final StringSqlExpressionBuilder name;
@override
List<SqlExpressionBuilder> get expressionBuilders {
return [id, createdAt, updatedAt, name];
}
}
class AuthorQueryValues extends MapQueryValues {
@override
Map<String, String> get casts {
return {};
}
String? get id {
return (values['id'] as String?);
}
set id(String? value) => values['id'] = value;
DateTime? get createdAt {
return (values['created_at'] as DateTime?);
}
set createdAt(DateTime? value) => values['created_at'] = value;
DateTime? get updatedAt {
return (values['updated_at'] as DateTime?);
}
set updatedAt(DateTime? value) => values['updated_at'] = value;
String? get name {
return (values['name'] as String?);
}
set name(String? value) => values['name'] = value;
void copyFrom(Author model) {
createdAt = model.createdAt;
updatedAt = model.updatedAt;
name = model.name;
}
}
// **************************************************************************
// JsonModelGenerator
// **************************************************************************
@generatedSerializable
class Book extends _Book {
Book(
{this.id,
this.createdAt,
this.updatedAt,
this.author,
this.partnerAuthor,
this.name});
/// A unique identifier corresponding to this item.
@override
String? id;
/// The time at which this item was created.
@override
DateTime? createdAt;
/// The last time at which this item was updated.
@override
DateTime? updatedAt;
@override
_Author? author;
@override
_Author? partnerAuthor;
@override
String? name;
Book copyWith(
{String? id,
DateTime? createdAt,
DateTime? updatedAt,
_Author? author,
_Author? partnerAuthor,
String? name}) {
return Book(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
author: author ?? this.author,
partnerAuthor: partnerAuthor ?? this.partnerAuthor,
name: name ?? this.name);
}
@override
bool operator ==(other) {
return other is _Book &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.author == author &&
other.partnerAuthor == partnerAuthor &&
other.name == name;
}
@override
int get hashCode {
return hashObjects([id, createdAt, updatedAt, author, partnerAuthor, name]);
}
@override
String toString() {
return 'Book(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, author=$author, partnerAuthor=$partnerAuthor, name=$name)';
}
Map<String, dynamic> toJson() {
return BookSerializer.toMap(this);
}
}
@generatedSerializable
class Author extends _Author {
Author({this.id, this.createdAt, this.updatedAt, this.name = 'Tobe Osakwe'});
/// A unique identifier corresponding to this item.
@override
String? id;
/// The time at which this item was created.
@override
DateTime? createdAt;
/// The last time at which this item was updated.
@override
DateTime? updatedAt;
@override
String? name;
Author copyWith(
{String? id, DateTime? createdAt, DateTime? updatedAt, String? name}) {
return Author(
id: id ?? this.id,
createdAt: createdAt ?? this.createdAt,
updatedAt: updatedAt ?? this.updatedAt,
name: name ?? this.name);
}
@override
bool operator ==(other) {
return other is _Author &&
other.id == id &&
other.createdAt == createdAt &&
other.updatedAt == updatedAt &&
other.name == name;
}
@override
int get hashCode {
return hashObjects([id, createdAt, updatedAt, name]);
}
@override
String toString() {
return 'Author(id=$id, createdAt=$createdAt, updatedAt=$updatedAt, name=$name)';
}
Map<String, dynamic> toJson() {
return AuthorSerializer.toMap(this);
}
}
// **************************************************************************
// SerializerGenerator
// **************************************************************************
const BookSerializer bookSerializer = BookSerializer();
class BookEncoder extends Converter<Book, Map> {
const BookEncoder();
@override
Map convert(Book model) => BookSerializer.toMap(model);
}
class BookDecoder extends Converter<Map, Book> {
const BookDecoder();
@override
Book convert(Map map) => BookSerializer.fromMap(map);
}
class BookSerializer extends Codec<Book, Map> {
const BookSerializer();
@override
BookEncoder get encoder => const BookEncoder();
@override
BookDecoder get decoder => const BookDecoder();
static Book fromMap(Map map) {
return Book(
id: map['id'] as String?,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString()))
: null,
author: map['author'] != null
? AuthorSerializer.fromMap(map['author'] as Map)
: null,
partnerAuthor: map['partner_author'] != null
? AuthorSerializer.fromMap(map['partner_author'] as Map)
: null,
name: map['name'] as String?);
}
static Map<String, dynamic> toMap(_Book? model) {
if (model == null) {
return {};
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'author': AuthorSerializer.toMap(model.author),
'partner_author': AuthorSerializer.toMap(model.partnerAuthor),
'name': model.name
};
}
}
abstract class BookFields {
static const List<String> allFields = <String>[
id,
createdAt,
updatedAt,
author,
partnerAuthor,
name
];
static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String author = 'author';
static const String partnerAuthor = 'partner_author';
static const String name = 'name';
}
const AuthorSerializer authorSerializer = AuthorSerializer();
class AuthorEncoder extends Converter<Author, Map> {
const AuthorEncoder();
@override
Map convert(Author model) => AuthorSerializer.toMap(model);
}
class AuthorDecoder extends Converter<Map, Author> {
const AuthorDecoder();
@override
Author convert(Map map) => AuthorSerializer.fromMap(map);
}
class AuthorSerializer extends Codec<Author, Map> {
const AuthorSerializer();
@override
AuthorEncoder get encoder => const AuthorEncoder();
@override
AuthorDecoder get decoder => const AuthorDecoder();
static Author fromMap(Map map) {
return Author(
id: map['id'] as String?,
createdAt: map['created_at'] != null
? (map['created_at'] is DateTime
? (map['created_at'] as DateTime)
: DateTime.parse(map['created_at'].toString()))
: null,
updatedAt: map['updated_at'] != null
? (map['updated_at'] is DateTime
? (map['updated_at'] as DateTime)
: DateTime.parse(map['updated_at'].toString()))
: null,
name: map['name'] as String? ?? 'Tobe Osakwe');
}
static Map<String, dynamic> toMap(_Author? model) {
if (model == null) {
return {};
}
return {
'id': model.id,
'created_at': model.createdAt?.toIso8601String(),
'updated_at': model.updatedAt?.toIso8601String(),
'name': model.name
};
}
}
abstract class AuthorFields {
static const List<String> allFields = <String>[
id,
createdAt,
updatedAt,
name
];
static const String id = 'id';
static const String createdAt = 'created_at';
static const String updatedAt = 'updated_at';
static const String name = 'name';
}

View file

@ -1,38 +0,0 @@
library angel3_orm_generator.test.models.user;
import 'package:angel3_migration/angel3_migration.dart';
import 'package:angel3_orm/angel3_orm.dart';
import 'package:angel3_serialize/angel3_serialize.dart';
import 'package:optional/optional.dart';
part 'user.g.dart';
@serializable
@orm
abstract class _User extends Model {
String? get username;
String? get password;
String? get email;
@ManyToMany(_RoleUser)
List<_Role> get roles;
}
@serializable
@orm
abstract class _RoleUser {
@belongsTo
_Role? get role;
@belongsTo
_User? get user;
}
@serializable
@orm
abstract class _Role extends Model {
String? name;
@ManyToMany(_RoleUser)
List<_User>? get users;
}

File diff suppressed because it is too large Load diff

View file

@ -1,12 +0,0 @@
import 'dart:io';
import 'package:io/ansi.dart';
void printSeparator(String title) {
var b = StringBuffer('===' + title.toUpperCase());
for (var i = b.length; i < stdout.terminalColumns - 3; i++) {
b.write('=');
}
for (var i = 0; i < 3; i++) {
print(magenta.wrap(b.toString()));
}
}

View file

@ -1,31 +0,0 @@
name: orm_builder
version: 1.0.0
description: ORM Builder Testing
published_to: none
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
angel3_migration: ^4.0.0
angel3_model: ^3.1.0
angel3_orm: ^4.0.0
angel3_serialize: ^4.1.0
io: ^1.0.0
test: ^1.17.4
collection: ^1.15.0
optional: ^6.0.0
dev_dependencies:
angel3_orm_generator: ^4.1.0
angel3_framework: ^4.2.0
build_runner: ^2.0.1
lints: ^1.0.0
dependency_overrides:
# angel3_migration_runner:
# path: ../angel_migration_runner
angel3_orm:
path: ../angel_orm
angel3_migration:
path: ../angel_migration
angel3_orm_generator:
path: ../angel_orm_generator
angel3_serialize:
path: ../../serialize/angel_serialize