Skip to content

Commit

Permalink
feat: working tess
Browse files Browse the repository at this point in the history
  • Loading branch information
darraghoriordan committed Mar 15, 2023
1 parent 08ee93a commit 7407855
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ export class AuthenticationTokenManager {
parameters: TestUserConfiguration
): Promise<string> {
try {
console.log("Getting new token", parameters);
if (!parameters.username) {
throw new Error("No user username provided");
}
Expand Down
15 changes: 14 additions & 1 deletion apps/backend-e2e/src/miller-tests/emailClient.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { EmailClientApi } from "@use-miller/shared-api-client";
import {
ApplicationSupportApi,
EmailClientApi,
} from "@use-miller/shared-api-client";
import { ApiClientFactory } from "./commonDataModels/ApiClientFactory";
import { TestUserAccounts } from "./commonDataModels/AuthenticationTokenManager";

describe("When using the email client", () => {
const emailClientApi =
Expand All @@ -9,5 +13,14 @@ describe("When using the email client", () => {
const result = await emailClientApi.emailClientControllerVerify();

expect(result.result).toBe(true);
}, 20_000);

afterAll(async () => {
const applicationSupportApi =
ApiClientFactory.getAuthenticatedApiInstance(
ApplicationSupportApi,
TestUserAccounts.SUPER_USER
);
await applicationSupportApi.superPowersControllerResetDatabase();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ describe("When inviting users", () => {
});

afterAll(async () => {
const applicationSupportApi =
ApiClientFactory.getAuthenticatedApiInstance(
ApplicationSupportApi,
TestUserAccounts.SUPER_USER
);
await applicationSupportApi.superPowersControllerResetDatabase();
});
});
26 changes: 16 additions & 10 deletions apps/backend-e2e/src/miller-tests/new-user-flow.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import {
ApplicationSupportApi,
Organisation,
OrganisationMembershipsApi,
OrganisationsApi,
OrganisationSubscriptionRecord,
OrganisationSubscriptionsApi,
OrganisationSubscriptionsControllerAddSubscriptionRequest,
User,
UsersApi,
} from "@use-miller/shared-api-client";
import { ApiClientFactory } from "./commonDataModels/ApiClientFactory";
import { TestUserAccounts } from "./commonDataModels/AuthenticationTokenManager.js";
import { TestUserAccounts } from "./commonDataModels/AuthenticationTokenManager";

// This follows a user through the first steps when they hit
// the api for the first time.

describe("When getting a user the first time", () => {
const userApi = ApiClientFactory.getAuthenticatedApiInstance(UsersApi);
const orgApi =
ApiClientFactory.getAuthenticatedApiInstance(OrganisationsApi);
const orgMembershipsApi = ApiClientFactory.getAuthenticatedApiInstance(
OrganisationMembershipsApi
);

const subscriptionsApi = ApiClientFactory.getAuthenticatedApiInstance(
OrganisationSubscriptionsApi
);
Expand All @@ -31,18 +31,15 @@ describe("When getting a user the first time", () => {
OrganisationSubscriptionsApi,
TestUserAccounts.SUPER_USER
);

let foundUser: User | undefined;

it("the user is initialised", async () => {
foundUser = await userApi.userControllerFindOne({
const foundUser = await userApi.userControllerFindOne({
uuid: "me",
});
expect(foundUser).toMatchObject({
auth0UserId: expect.any(String),
// auth0UserId: expect.any(String),
email: "testbasic@testbasic.com",
});
});
}, 30_000);

it("any path other than 'me' is treated as an id", async () => {
await expect(() =>
Expand All @@ -67,7 +64,7 @@ describe("When getting a user the first time", () => {
orgUuid: org!.uuid,
});
expect(memberships).toHaveLength(1);
console.log("memberships", memberships);

expect(memberships[0]).toMatchObject({
roles: [
{
Expand Down Expand Up @@ -140,4 +137,13 @@ describe("When getting a user the first time", () => {
expect(r.result).toBe(true);
}
});

afterAll(async () => {
const applicationSupportApi =
ApiClientFactory.getAuthenticatedApiInstance(
ApplicationSupportApi,
TestUserAccounts.SUPER_USER
);
await applicationSupportApi.superPowersControllerResetDatabase();
});
});
21 changes: 9 additions & 12 deletions apps/backend-e2e/src/preRun.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import dotenv from "dotenv";
import {
AuthenticationTokenManager,
TestUserAccounts,
} from "./miller-tests/commonDataModels/AuthenticationTokenManager";
import { AuthenticationTokenManager } from "./miller-tests/commonDataModels/AuthenticationTokenManager";
dotenv.config();
// This is a hack for tests
import { TextEncoder, TextDecoder } from "util";
Expand All @@ -15,13 +12,13 @@ global.TextDecoder = TextDecoder as any;
// loads our auth token once into the static class we use to build requests
await AuthenticationTokenManager.init();

for (const key of Object.keys(TestUserAccounts)) {
console.log(
`Using ${key} token: \r%s\r\r`,
AuthenticationTokenManager.getAccessToken(
TestUserAccounts[key as keyof typeof TestUserAccounts]
)
);
}
// for (const key of Object.keys(TestUserAccounts)) {
// console.log(
// `Using ${key} token: \r%s\r\r`,
// AuthenticationTokenManager.getAccessToken(
// TestUserAccounts[key as keyof typeof TestUserAccounts]
// )
// );
// }

export {};
2 changes: 1 addition & 1 deletion apps/backend-e2e/tmp-tokens/basic-user-api-test-token.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Il9RUGlhWnJaOVMxSDNpNmhLQXFQeCJ9.eyJpc3MiOiJodHRwczovL3VzZW1pbGxlcmRldi5hdS5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NjNlMGVlNDc0OGNjNmE3ZDQzMmRlMjUwIiwiYXVkIjpbImJhY2tlbmQtYXBpLWF1ZGllbmNlIiwiaHR0cHM6Ly91c2VtaWxsZXJkZXYuYXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTY3ODc4MTgzMiwiZXhwIjoxNjc4ODY4MjMyLCJhenAiOiJVbzNjZHp3bVpUOWtMenF4TGtJbnZ5cVFZbzRsVWVqMiIsInNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUgb2ZmbGluZV9hY2Nlc3MiLCJndHkiOiJwYXNzd29yZCIsInBlcm1pc3Npb25zIjpbXX0.M3r93hrJUSFJxC6uDWKtipq1fYzuyuj7u4_BNRAycq-VF3FupkNf_6kjNx-Sk6wL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07Zw0BMt9WhoofeppMVraKb38lTvybbFxsuYhlTAuPfi9bygGkjuxlNe8MeuAaDqhH_On0_MoMra9S6FkpDHDEkrBgUKjQPgPU_2uBgg","date_received":"2023-03-15T08:38:11.788Z","expires_in":86400,"token_type":"Bearer"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Il9RUGlhWnJaOVMxSDNpNmhLQXFQeCJ9.eyJpc3MiOiJodHRwczovL3VzZW1pbGxlcmRldi5hdS5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NjQwZDQ4NDgxZWI5MDBmYjM3YmFhYjNlIiwiYXVkIjpbImJhY2tlbmQtYXBpLWF1ZGllbmNlIiwiaHR0cHM6Ly91c2VtaWxsZXJkZXYuYXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTY3ODc4MTgzMywiZXhwIjoxNjc4ODY4MjMzLCJhenAiOiJVbzNjZHp3bVpUOWtMenF4TGtJbnZ5cVFZbzRsVWVqMiIsInNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUgb2ZmbGluZV9hY2Nlc3MiLCJndHkiOiJwYXNzd29yZCIsInBlcm1pc3Npb25zIjpbXX0.sREY11SSWJxakKVEEjJeKi5e3FCsoyqD-ZhwQbGn1cgwhgS49-Z6HvwfJeooSqgD9MTtVytEMgNAlcYLkt0kIEtf_8VouY_ka4da4-Td0WCmReyd0rgiT17tgzYqyeqF7Py8tyJ0MTy9wFx_WvPc1c5VcCODv_V1LPCiX7CL-G8pdKoXYOudEX8qK4sDEChdURFj1YDdwYw7zjpv6zEbdEy0QEGMUFoKAu03aXdQN4ime29M4m6TPLI4jsb887NDd8kA2eOco_RSx-oX9wzX_WNqjz6IONiki31-vmYMq938hIy_J9DUYZe4gGopVw9K0B-L4twePPrBfXUdyAY1OQ","date_received":"2023-03-14T08:17:13.324Z","expires_in":86400,"token_type":"Bearer"}
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Il9RUGlhWnJaOVMxSDNpNmhLQXFQeCJ9.eyJpc3MiOiJodHRwczovL3VzZW1pbGxlcmRldi5hdS5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NjQwZDQ4NDgxZWI5MDBmYjM3YmFhYjNlIiwiYXVkIjpbImJhY2tlbmQtYXBpLWF1ZGllbmNlIiwiaHR0cHM6Ly91c2VtaWxsZXJkZXYuYXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTY3ODg2OTQ5MiwiZXhwIjoxNjc4OTU1ODkyLCJhenAiOiJVbzNjZHp3bVpUOWtMenF4TGtJbnZ5cVFZbzRsVWVqMiIsInNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUgb2ZmbGluZV9hY2Nlc3MiLCJndHkiOiJwYXNzd29yZCIsInBlcm1pc3Npb25zIjpbXX0.DeOX4NWW6_JSg3r1o_eWdne24fPsMtLmo6UK__-o1f4rbZdn7X8dKvaSxYlQRi3TM4GPUb9eZ1ZW3_sUoeuotJ0yGioaYnLbxj5lWJkUA-GfRPp7atCIYWyYCkzWStjzIuYRmhYFX9jzVpDIPpFrPFW6MEPD6ArpnzkQ6Ht5kk9m-enFKVttX1c4YmvsGuAIIdIxoMBBRPSC4YD3mK2eLL5E2WotBunRXrvjRPBeKVUcBmiMQC6JsDwPCbTIn27LBLC9Fz0h3Ln_ooEMI4Y3zIxuVTMJicwHdVF5BopQB23JzTxlD2iIhAY17cZtC8xeTVnIEelyRg-uOxCo2o7MEw","date_received":"2023-03-15T08:38:12.076Z","expires_in":86400,"token_type":"Bearer"}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"access_token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6Il9RUGlhWnJaOVMxSDNpNmhLQXFQeCJ9.eyJpc3MiOiJodHRwczovL3VzZW1pbGxlcmRldi5hdS5hdXRoMC5jb20vIiwic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JhY2tlbmQtYXBpLWF1ZGllbmNlIiwiaHR0cHM6Ly91c2VtaWxsZXJkZXYuYXUuYXV0aDAuY29tL3VzZXJpbmZvIl0sImlhdCI6MTY3ODg2OTQ5MSwiZXhwIjoxNjc4OTU1ODkxLCJhenAiOiJVbzNjZHp3bVpUOWtMenF4TGtJbnZ5cVFZbzRsVWVqMiIsInNjb3BlIjoib3BlbmlkIGVtYWlsIHByb2ZpbGUgcmVhZDpvd24gb2ZmbGluZV9hY2Nlc3MiLCJndHkiOiJwYXNzd29yZCIsInBlcm1pc3Npb25zIjpbIm1vZGlmeTphbGwiLCJtb2RpZnk6b3JnIiwibW9kaWZ5Om93biIsInJlYWQ6YWxsIiwicmVhZDpvcmciLCJyZWFkOm93biJdfQ.MbG-O9u1WRGbYh_O_Bqdjdob49feu1wBY6ybceiStrrgJTkLAjxTOiEgF40eLWGD7a5l7uxZuN7mtoN8MMTh6kATx1SRckJYBy2YNlj85qfGTfAWO8eNMRsSAFGhmYyRg0JsAswroVOv7Tnm-2abgBZh95Hgo3HrnYNu4H8TFi-vc_-lxyMtNAF9Z1D2RjT2mLKKIWvWRQs3xaszdZSM9cHS8WSZqcG0C9SsmdTuh7iB428zXRweGrrebGW8SAreKmVFPtHRQqOaU-IogzocnilUltMLZjrSIwLYrl0GQNUJeToTleQYz-Tsk3chQGenLLsf9od58UrAjDJECDeGjA","date_received":"2023-03-15T08:38:11.443Z","expires_in":86400,"token_type":"Bearer"}

0 comments on commit 7407855

Please sign in to comment.