This file contains hidden or 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
| package com.example.redisspringratelimiting.controller; | |
| import com.example.redisspringratelimiting.config.RateLimitConfig; | |
| import com.example.redisspringratelimiting.model.ApiResponse; | |
| import io.github.bucket4j.Bucket; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.web.bind.annotation.GetMapping; | |
| import org.springframework.web.bind.annotation.PathVariable; | |
| import org.springframework.web.bind.annotation.RequestMapping; |
This file contains hidden or 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
| package com.example.redisspringratelimiting; | |
| import com.example.redisspringratelimiting.config.RateLimitConfig; | |
| import com.example.redisspringratelimiting.config.RedisConfig; | |
| import org.junit.jupiter.api.Test; | |
| import org.springframework.boot.test.context.SpringBootTest; | |
| import org.springframework.boot.test.mock.mockito.MockBean; | |
| import org.springframework.http.ResponseEntity; | |
| import org.springframework.web.client.HttpClientErrorException; | |
| import org.springframework.web.client.RestTemplate; |
This file contains hidden or 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
| package com.example.redisspringratelimiting.config; | |
| import io.github.bucket4j.Bandwidth; | |
| import io.github.bucket4j.Bucket; | |
| import io.github.bucket4j.BucketConfiguration; | |
| import io.github.bucket4j.Refill; | |
| import io.github.bucket4j.distributed.proxy.ProxyManager; | |
| import org.springframework.beans.factory.annotation.Autowired; | |
| import org.springframework.context.annotation.Configuration; |
This file contains hidden or 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
| package com.example.redisspringratelimiting.config; | |
| import com.giffing.bucket4j.spring.boot.starter.config.cache.SyncCacheResolver; | |
| import com.giffing.bucket4j.spring.boot.starter.config.cache.jcache.JCacheCacheResolver; | |
| import io.github.bucket4j.distributed.proxy.ProxyManager; | |
| import io.github.bucket4j.grid.jcache.JCacheProxyManager; | |
| import org.redisson.config.Config; | |
| import org.redisson.jcache.configuration.RedissonConfiguration; | |
| import org.redisson.spring.starter.RedissonAutoConfiguration; | |
| import org.springframework.context.annotation.Bean; |
This file contains hidden or 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
| plugins { | |
| id 'java' | |
| id 'org.springframework.boot' version '2.7.5' | |
| id 'io.spring.dependency-management' version '1.0.15.RELEASE' | |
| } | |
| group = 'com.example' | |
| version = '0.0.1-SNAPSHOT' | |
| sourceCompatibility = '11' |
This file contains hidden or 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
| name: run api testing | |
| on: | |
| push: | |
| branches: [dev, stage, master] | |
| pull_request: | |
| branches: [master] | |
| jobs: | |
| api-test: | |
| runs-on: ubuntu-latest |
This file contains hidden or 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
| const Sequelize = require("sequelize"); | |
| const { | |
| DATABASE, | |
| DB_USER, | |
| DB_HMAC, | |
| DB_HOST, | |
| DB_PORT, | |
| DB_DIALECT, | |
| DB_POOL_CONNECTION_LIMIT, | |
| DB_POOL_IDLE_TIMEOUT, |
This file contains hidden or 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
| const { DataTypes } = require("sequelize"); | |
| module.exports = (sequelizeInstance) => { | |
| const tasks = sequelizeInstance.define("tasks", { | |
| id: { | |
| type: DataTypes.INTEGER, | |
| autoIncrement: true, | |
| primaryKey: true, | |
| }, | |
| title: { | |
| type: DataTypes.STRING, |
This file contains hidden or 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
| describe("/POST task", () => { | |
| it("it SHOULD NOT POST a task without title field", (done) => { | |
| let taskPayload = { | |
| description: "J.R.R. Tolkien", | |
| created_by: "[email protected]", | |
| }; | |
| chai.request(app) | |
| .post("/create_task") | |
| .send(taskPayload) | |
| .end((err, res) => { |
This file contains hidden or 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
| process.env.NODE_ENV = "test"; | |
| const app = require("../src/app.js"); | |
| const models = require("../src/models/index"); | |
| const { QueryTypes } = require("sequelize"); | |
| const sequelizeInstance = models.sequelizeInstance; | |
| //Require the dev-dependencies | |
| let chai = require("chai"); | |
| let chaiHttp = require("chai-http"); | |
| let should = chai.should(); |
NewerOlder