-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12104 from Budibase/features/per-user-per-creator…
…-realease2 [Added] Per user per creator changes
- Loading branch information
Showing
17 changed files
with
236 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const _ = require('lodash/fp') | ||
const {structures} = require("../../../tests") | ||
|
||
jest.mock("../../../src/context") | ||
jest.mock("../../../src/db") | ||
|
||
const context = require("../../../src/context") | ||
const db = require("../../../src/db") | ||
|
||
const {getCreatorCount} = require('../../../src/users/users') | ||
|
||
describe("Users", () => { | ||
|
||
let getGlobalDBMock | ||
let getGlobalUserParamsMock | ||
let paginationMock | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
|
||
getGlobalDBMock = jest.spyOn(context, "getGlobalDB") | ||
getGlobalUserParamsMock = jest.spyOn(db, "getGlobalUserParams") | ||
paginationMock = jest.spyOn(db, "pagination") | ||
}) | ||
|
||
it("Retrieves the number of creators", async () => { | ||
const getUsers = (offset, limit, creators = false) => { | ||
const range = _.range(offset, limit) | ||
const opts = creators ? {builder: {global: true}} : undefined | ||
return range.map(() => structures.users.user(opts)) | ||
} | ||
const page1Data = getUsers(0, 8) | ||
const page2Data = getUsers(8, 12, true) | ||
getGlobalDBMock.mockImplementation(() => ({ | ||
name : "fake-db", | ||
allDocs: () => ({ | ||
rows: [...page1Data, ...page2Data] | ||
}) | ||
})) | ||
paginationMock.mockImplementationOnce(() => ({ | ||
data: page1Data, | ||
hasNextPage: true, | ||
nextPage: "1" | ||
})) | ||
paginationMock.mockImplementation(() => ({ | ||
data: page2Data, | ||
hasNextPage: false, | ||
nextPage: undefined | ||
})) | ||
const creatorsCount = await getCreatorCount() | ||
expect(creatorsCount).toBe(4) | ||
expect(paginationMock).toHaveBeenCalledTimes(2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule pro
updated
from 044bec to 570d14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
packages/server/src/migrations/functions/usageQuotas/syncCreators.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import { users } from "@budibase/backend-core" | ||
import { quotas } from "@budibase/pro" | ||
import { QuotaUsageType, StaticQuotaName } from "@budibase/types" | ||
|
||
export const run = async () => { | ||
const creatorCount = await users.getCreatorCount() | ||
console.log(`Syncing creator count: ${creatorCount}`) | ||
await quotas.setUsage( | ||
creatorCount, | ||
StaticQuotaName.CREATORS, | ||
QuotaUsageType.STATIC | ||
) | ||
} |
Oops, something went wrong.