Skip to content

Commit

Permalink
Use string id in test
Browse files Browse the repository at this point in the history
  • Loading branch information
codekeyz committed May 10, 2024
1 parent 10e6b82 commit b165fa6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 12 deletions.
5 changes: 3 additions & 2 deletions _tests_/lib/src/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,9 @@ class Post extends Entity<Post> {

@table
class PostComment extends Entity<PostComment> {
@primaryKey
final int id;
@PrimaryKey(autoIncrement: false)
final String id;

final String comment;

@bindTo(Post, onDelete: ForeignKeyAction.cascade)
Expand Down
1 change: 1 addition & 0 deletions _tests_/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ environment:

dependencies:
build_runner: ^2.4.9
uuid: ^4.4.0
yaroorm:
path: ../
43 changes: 33 additions & 10 deletions _tests_/test/integration/e2e_relation.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:test/test.dart';
import 'package:uuid/uuid.dart';
import 'package:yaroorm/yaroorm.dart';
import 'package:yaroorm_tests/src/models.dart';
import 'package:yaroorm_tests/test_data.dart';
Expand All @@ -7,6 +8,8 @@ import 'package:yaroorm/src/reflection.dart';

import '../util.dart';

final uuid = Uuid();

void runRelationsE2ETest(String connectionName) {
final driver = DB.driver(connectionName);

Expand Down Expand Up @@ -51,15 +54,24 @@ void runRelationsE2ETest(String connectionName) {
orderBy: [OrderPostBy.title(order: OrderDirection.desc)],
);
expect(posts, hasLength(3));
expect(posts.map((e) => {'id': e.id, 'title': e.title, 'desc': e.description, 'userId': e.userId}), [
{'id': 3, 'title': 'Coo Kie 3', 'desc': 'foo bar 6', 'userId': 1},
{'id': 2, 'title': 'Bee Moo 2', 'desc': 'foo bar 5', 'userId': 1},
{'id': 1, 'title': 'Aoo bar 1', 'desc': 'foo bar 4', 'userId': 1}
]);
expect(
posts.map((e) => {
'id': e.id,
'title': e.title,
'desc': e.description,
'userId': e.userId
}),
[
{'id': 3, 'title': 'Coo Kie 3', 'desc': 'foo bar 6', 'userId': 1},
{'id': 2, 'title': 'Bee Moo 2', 'desc': 'foo bar 5', 'userId': 1},
{'id': 1, 'title': 'Aoo bar 1', 'desc': 'foo bar 4', 'userId': 1}
]);
});

test('should fetch posts with owner', () async {
final posts = await PostQuery.driver(driver).withRelations((post) => [post.owner]).findMany();
final posts = await PostQuery.driver(driver)
.withRelations((post) => [post.owner])
.findMany();

final owner = await posts.first.owner.value;
expect(
Expand All @@ -75,14 +87,25 @@ void runRelationsE2ETest(String connectionName) {
var comments = await post!.comments.get();
expect(comments, isEmpty);

final firstId = uuid.v4();
final secondId = uuid.v4();

await post.comments.insertMany([
NewPostCommentForPost(comment: 'This post looks abit old'),
NewPostCommentForPost(comment: 'oh, another comment'),
NewPostCommentForPost(
id: firstId,
comment: 'This post looks abit old',
),
NewPostCommentForPost(
id: secondId,
comment: 'oh, another comment',
),
]);

comments = await post.comments.get();

expect(comments.every((e) => e.postId == post.id), isTrue);
expect(comments.map((e) => e.id), containsAll([firstId, secondId]));

expect(
comments.map((c) => {
'id': c.id,
Expand Down Expand Up @@ -120,8 +143,8 @@ void runRelationsE2ETest(String connectionName) {
expect(anotherUserPost.userId, anotherUser.id);

await anotherUserPost.comments.insertMany([
NewPostCommentForPost(comment: 'ah ah'),
NewPostCommentForPost(comment: 'oh oh'),
NewPostCommentForPost(id: uuid.v4(), comment: 'ah ah'),
NewPostCommentForPost(id: uuid.v4(), comment: 'oh oh'),
]);

expect(await anotherUserPost.comments.get(), hasLength(2));
Expand Down

0 comments on commit b165fa6

Please sign in to comment.