Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong initialization of cached groups in Group service #330

Merged
merged 1 commit into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/api/src/app/groups/groups.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe("GroupsService", () => {
}).compile()

groupsService = await module.resolve(GroupsService)
await groupsService.initialize()

invitesService = await module.resolve(InvitesService)

const { id } = await groupsService.createGroup(
Expand Down Expand Up @@ -723,4 +725,17 @@ describe("GroupsService", () => {
await expect(fun).rejects.toThrow("You are not the admin")
})
})

describe("# initialize", () => {
it("Should initialize the cached groups", async () => {
const currentCachedGroups = await groupsService.getGroups()

await groupsService.initialize()

const updatedCachedGroups = await groupsService.getGroups()

expect(currentCachedGroups).toHaveLength(updatedCachedGroups.length)
expect(currentCachedGroups).toStrictEqual(updatedCachedGroups)
})
})
})
12 changes: 9 additions & 3 deletions apps/api/src/app/groups/groups.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ export class GroupsService {
process.env.BACKEND_PRIVATE_KEY as string,
process.env.INFURA_API_KEY as string
)
}

this._cacheGroups()
/**
* Initialises the service, caches groups and may sync contract
* groups if required.
*/
async initialize() {
await this._cacheGroups()

/* istanbul ignore next */
if (process.env.NODE_ENV !== "test") {
setTimeout(() => {
this._syncContractGroups()
setTimeout(async () => {
await this._syncContractGroups()
}, 5000)
}
}
Expand Down
4 changes: 4 additions & 0 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import { NestFactory } from "@nestjs/core"
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger"
import { ironSession } from "iron-session/express"
import { AppModule } from "./app/app.module"
import { GroupsService } from "./app/groups/groups.service"

async function bootstrap() {
const app = await NestFactory.create(AppModule)

const groupService = app.get(GroupsService)
await groupService.initialize()

app.useGlobalPipes(
new ValidationPipe({
whitelist: true,
Expand Down
Loading