nestjs-oauth2
Version:
NestJS OAuth2 Client
148 lines (147 loc) • 7.28 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@nestjs/common");
const core_1 = require("@nestjs/core");
const oauth_1 = require("src/oauth");
const providers_1 = require("src/providers");
const request = require("supertest");
describe("OAuthModule Initialization", () => {
describe("forFeature", () => {
it("should compile", () => __awaiter(void 0, void 0, void 0, function* () {
let TestController = class TestController {
get() {
return "";
}
};
__decorate([
(0, common_1.Get)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], TestController.prototype, "get", null);
TestController = __decorate([
(0, common_1.Controller)()
], TestController);
let TestModule = class TestModule {
};
TestModule = __decorate([
(0, common_1.Module)({
imports: [
oauth_1.OAuthModule.forFeature({
providers: [
Object.assign(Object.assign({}, providers_1.spotifyOptions), { clientId: "clientId", clientSecret: "clientSecret", scope: "user-read-private user-read-email", redirectOrigin: "http://localhost:3000" }),
],
}),
],
controllers: [TestController],
})
], TestModule);
const app = yield core_1.NestFactory.create(TestModule);
const server = app.getHttpServer();
yield app.init();
yield request(server).get("/").expect(200);
yield app.close();
}));
it("should compile with oauth controller", () => __awaiter(void 0, void 0, void 0, function* () {
let TestModule = class TestModule {
};
TestModule = __decorate([
(0, common_1.Module)({
imports: [
oauth_1.OAuthModule.forFeature({
providers: [
Object.assign(Object.assign({}, providers_1.spotifyOptions), { clientId: "clientId", clientSecret: "clientSecret", scope: "user-read-private user-read-email", redirectOrigin: "http://localhost:3000" }),
],
}),
],
controllers: [oauth_1.OAuthController],
})
], TestModule);
const app = yield core_1.NestFactory.create(TestModule);
const server = app.getHttpServer();
yield app.init();
yield request(server).get("/oauth/spotify").expect(302);
yield app.close();
}));
});
describe("forFeatureAsync", () => {
it("should compile", () => __awaiter(void 0, void 0, void 0, function* () {
let TestController = class TestController {
get() {
return "";
}
};
__decorate([
(0, common_1.Get)(),
__metadata("design:type", Function),
__metadata("design:paramtypes", []),
__metadata("design:returntype", void 0)
], TestController.prototype, "get", null);
TestController = __decorate([
(0, common_1.Controller)()
], TestController);
let TestModule = class TestModule {
};
TestModule = __decorate([
(0, common_1.Module)({
imports: [
oauth_1.OAuthModule.forFeatureAsync({
useFactory: () => ({
providers: [
Object.assign(Object.assign({}, providers_1.spotifyOptions), { clientId: "clientId", clientSecret: "clientSecret", scope: "user-read-private user-read-email", redirectOrigin: "http://localhost:3000" }),
],
}),
}),
],
controllers: [TestController],
})
], TestModule);
const app = yield core_1.NestFactory.create(TestModule);
const server = app.getHttpServer();
yield app.init();
yield request(server).get("/").expect(200);
yield app.close();
}));
it("should compile with oauth controller", () => __awaiter(void 0, void 0, void 0, function* () {
let TestModule = class TestModule {
};
TestModule = __decorate([
(0, common_1.Module)({
imports: [
oauth_1.OAuthModule.forFeatureAsync({
useFactory: () => ({
providers: [
Object.assign(Object.assign({}, providers_1.spotifyOptions), { clientId: "clientId", clientSecret: "clientSecret", scope: "user-read-private user-read-email", redirectOrigin: "http://localhost:3000" }),
],
}),
}),
],
controllers: [oauth_1.OAuthController],
})
], TestModule);
const app = yield core_1.NestFactory.create(TestModule);
const server = app.getHttpServer();
yield app.init();
yield request(server).get("/oauth/spotify").expect(302);
yield app.close();
}));
});
});