Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
intrn(database): found post word factory
Browse files Browse the repository at this point in the history
  • Loading branch information
Angelo Magtoto committed Oct 15, 2022
1 parent 8b2af0a commit 6515dde
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions t/helpers/factories/found_post_word.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* @description This module should not be used in production code. It only for testing purposes.
*/
import type { ModelCtor } from "%/types/dependent"
import type { GeneratedData } from "~/types/dependent"
import type {
FoundPostWordResourceIdentifier,
FoundPostWordAttributes,
DeserializedFoundPostWordResource,
DeserializedFoundPostWordDocument,
DeserializedFoundPostWordListDocument,
FoundPostWordResource,
FoundPostWordDocument,
FoundPostWordListDocument
} from "$/types/documents/found_post_word"

import ProfanityFilter from "%/models/profanity_filter"
import Post from "%/models/post"
import ProfanityFilterFactory from "~/factories/profanity_filter"
import BaseFactory from "~/factories/base"
import PostFactory from "~/factories/post"
import FoundPostWord from "%/models/found_post_word"
import FoundPostWordTransformer from "%/transformers/found_post_word"

export default class FoundPostWordFactory extends BaseFactory<
FoundPostWord,
FoundPostWordResourceIdentifier<"read">,
FoundPostWordAttributes<"serialized">,
FoundPostWordAttributes<"deserialized">,
FoundPostWordResource,
DeserializedFoundPostWordResource,
FoundPostWordDocument,
FoundPostWordListDocument,
DeserializedFoundPostWordDocument,
DeserializedFoundPostWordListDocument
> {
#profanityFilterGenerator: () =>
Promise<ProfanityFilter> = async() => await new ProfanityFilterFactory().insertOne()

#postGenerator: () => Promise<Post>
= async() => await new PostFactory().insertOne()

get model(): ModelCtor<FoundPostWord> { return FoundPostWord }

get transformer(): FoundPostWordTransformer { return new FoundPostWordTransformer() }

async generate(): GeneratedData<FoundPostWord> {
return {
"postID": (await this.#postGenerator()).id,
"profanityFilterID": (await this.#profanityFilterGenerator()).id
}
}

async attachRelatedModels(model: FoundPostWord): Promise<FoundPostWord> {
model.post = await Post.findByPk(model.postID) as Post
model.profanityFilter = await ProfanityFilter.findByPk(
model.profanityFilterID) as ProfanityFilter

return model
}

profanityFilter(generator: () => Promise<ProfanityFilter>): FoundPostWordFactory {
this.#profanityFilterGenerator = generator
return this
}

post(generator: () => Promise<Post>): FoundPostWordFactory {
this.#postGenerator = generator
return this
}
}

0 comments on commit 6515dde

Please sign in to comment.